Consider two files systems A and B , that use contiguous allocation and linked…
2022
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 nA and , nB respectively, then the value of nA + nB is_________.
Attempted by 57 students.
Show answer & explanation
Correct answer: 153
Key idea: Count disk reads and writes required for each allocation method when inserting one block between the 50th and 51st blocks of a 100-block file. The file control blocks and the new block's data are already in memory, and there are free blocks available at the end of the file.
Contiguous allocation: Blocks 51 through 100 (50 blocks) must be moved one position forward to make room.
Each moved block requires one read and one write (2 disk accesses per block), so moving 50 blocks costs 100 disk accesses. Writing the new block into its place adds 1 write, giving a total of 101 disk accesses for contiguous allocation.
Linked allocation: To insert after the 50th block, the file must be traversed to reach the 50th block, which requires reading 50 blocks.
After reaching the 50th block, we write the new block (1 write) and update the next pointer in the 50th block (1 write). This gives a total of 52 disk accesses for linked allocation (50 reads + 2 writes).
Therefore, the total number of disk accesses is 101 + 52 = 153.
A video solution is available for this question — log in and enroll to watch it.