'File allocation

Consider 2 file systems A and B, use contagious allocation and linked allocation respectively. The file size of 100 blocks is already stored in A and also in B. Consider inserting a new block in the middle of the file., between 50th and 51st blocks, 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 be nA and nB respectively, what would be the value of nA + nB?



Solution 1:[1]

In the case of contiguous allocation, we can directly traverse to the $50^{th}$ element as it is already given the file control blocks (Index in case of indexed allocation) is already present. Now, we need $50$ operations to read the rest of the $50 elements$ and another $50$ operations to write those $50$ blocks and $1$ operation is needed to write the new block. So, total operations in this case $50 + 50 + 1$

In the case of the Linked allocation. We need to traverse to the $50^{th} element$. Now, simply we have to change the pointers just like the Linked list(Adding element in the middle of Linked List) So, here it takes $50$ operations to read the first $50$ elements and $2$ operations to change the pointer of the $50^{th}$ block, and a new block. So, 52 operations in this case.

Therefore, $n_a = 101$, and $n_b = 52$.

\begin {align} $$n_a+n_b = 101+52 = 153$$ \end{align}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1