Skip to main content

GATE CSE 2022Operating System › I/O, Disk Scheduling & File SystemsVerified

GATE CSE 2022 PYQ: Consider two files systems A \text{A} A and B \text{B} B , that use contiguous allocation and linked…

Consider two files systems A\text{A} and B\text{B}, that use contiguous allocation and linked allocation, respectively. A file of size 100 blocks is already stored in A\text{A} and also in B\text{B}. Now, consider inserting a new block in the middle of the file (between 50th50^{th} and 51st51^{st} 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\text{A} and B\text{B} are nAn_{A} and nBn_{B}, respectively, then the value of nA+nBn_{A} + n_{B} is__________________.

    Answer

    153

    Approach

    Compare insertion cost under contiguous and linked allocation. For contiguous allocation, insertion forces all following blocks to be shifted to preserve contiguity. For linked allocation, only pointers change, but reaching the insertion point requires sequential traversal. The new block data is already in memory, and file control blocks are in memory, so no extra metadata or allocation I/O is counted.

    Contiguous allocation needs 50 block shifts (100 accesses) plus writing the new block (1), giving 101. Linked allocation needs 50 reads to reach the insertion point plus 2 writes to link the new block and update the previous block, giving 52. The required total is 153.

    Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.