Consider two files systems and , that use contiguous allocation and linked allocation, respectively. A file of size 100 blocks is already stored in and also in . 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 and are and , respectively, then the value of is ______.
GATE 2022 CS Q.63: solution and answer
Answer and solution
ANSWER
.
Official answer: 153Source: Official answer key, GATE 2022 CS (IIT Kharagpur)
File (contiguous). To open a gap after block 50, blocks 51 to 100 must each move one position towards the end: that is blocks. There are enough free blocks at the end, so block 101 is available.
Each moved block costs one read and one write, so accesses. Move from the last block backwards, so nothing is overwritten before it has been copied.
Writing the new block (already in memory) into the gap costs 1 access. So .
File (linked). There is no random access, so block 50 is reached by following pointers from the start. Reading blocks 1 to 50 costs 50 accesses (the file control block is in memory, so the first block's address is free).
Write the new block, with its pointer set to the old block 51: 1 access.
Block 50 is already in memory, so rewrite it with its pointer changed to the new block: 1 access. So .
.
KEY IDEA
Contiguous allocation must physically shift every block after the insertion point (a read and a write each), while linked allocation must walk to the insertion point and then change only two pointers.
WATCH OUT FOR
Forgetting that a shifted block costs two accesses (read and write), or forgetting to rewrite block 50 with the new pointer in the linked file.
From the GATE 2022 CS paper. Every question of this paper · Download the full paper · All 6 File systems & disks questions, with notes
More File systems & disks questions
- GATE 2018 CS Q.53 · NAT · 2 marksConsider a storage disk with 4 platters (numbered as 0, 1, 2 and 3), 200 cylinders (numbered as 0, 1…
- GATE 2026 CS1 Q.59 · NAT · 2 marksConsider a hard disk with a rotational speed of 15000 rpm. The time to move the read/write head from a track…
- GATE 2026 CS2 Q.53 · NAT · 2 marksTo keep track of free blocks in a file system, one of the two approaches is generally used – using bitmaps…
