Question
Consider two files systems A and B, that use contiguous allocation and linked allocation, respectively. A file of size 100 blocks is already stored in A and also in B. Now, consider inserting a new block in the middle of the file (between 50th and 51st block), whose data is already available in the memory. Assume that there are enough free blocks at the end of the file and that the file control blocks are already in memory. Let the number of disk accesses required to insert a block in the middle of the file in A and B are and , respectively, then the value of is_________.
Official answer and solution
- Official answer
- 153
- From
- Official GATE 2022 answer key
Solution
Calculate the disk read and write accesses required to insert a block in contiguous allocation versus linked allocation.
A file contains 100 blocks, and a new block is inserted between the 50th and 51st blocks.
-
In Contiguous Allocation (System A):
- The first 50 blocks remain in place.
- Blocks 51 through 100 (50 blocks) must be shifted backward by one position.
- Shifting each of these 50 blocks requires 1 disk read and 1 disk write: accesses.
- Writing the new block into position 51 requires 1 disk write.
- Total disk accesses for A: .
-
In Linked Allocation (System B):
- Pointers are stored within each block.
- To reach the 50th block, we must traverse the linked chain from block 1 to block 50: 50 disk reads.
- Once block 50 is in memory, its pointer is updated to point to the new block, and the new block is set to point to block 51.
- Writing the new block to disk requires 1 disk write.
- Writing the modified block 50 back to disk requires 1 disk write.
- Total disk accesses for B: .
-
Sum of accesses:
153
Forgetting that block 50 in linked allocation must be written back to disk after updating its next-block pointer.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2022 Computer Science and Information Technology (CS)
- Question
- 63 of 65
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.