Question:

Consider contiguous allocation of physical memory to processes using variable
partitioning scheme. Suppose there are 8 holes in the memory of sizes 20 KB, 4 KB,
25 KB, 18 KB, 7 KB, 9 KB, 15 KB, and 12 KB. Assume that no two holes are
adjacent. Two processes P1 of size 16 KB and P2 of size 9 KB arrive in that order,
and they are allocated memory using the best-fit technique. After allocating space
to P1 and P2, the number of holes of size less than 8 KB is ____________. (answer
in integer)
Note: 1K=210

Show Hint

Apply best-fit twice: first find the smallest hole \(\geq 16\) KB for P1 (it is 18 KB, leaving a 2 KB remainder), then find the smallest hole \(\geq 9\) KB for P2 (it is the 9 KB hole exactly, leaving no remainder). Update the hole list and count holes below 8 KB.
Updated On: Jul 7, 2026
Show Solution
collegedunia
Verified By Collegedunia

Correct Answer: 3

Solution and Explanation

We are given 8 holes in memory of sizes 20 KB, 4 KB, 25 KB, 18 KB, 7 KB, 9 KB, 15 KB and 12 KB. Two processes P1 (16 KB) and P2 (9 KB) arrive in that order and are allocated using the best-fit strategy, which always picks the smallest hole that is still large enough to hold the process.

Step 1: Allocate P1 (16 KB).

List the holes that are \(\geq 16\) KB: 20 KB, 25 KB, 18 KB. Among these, the smallest is 18 KB, so best-fit places P1 into the 18 KB hole.

Remaining size of that hole after allocation: \(18 - 16 = 2\) KB.

Updated hole list: 20, 4, 25, 2, 7, 9, 15, 12 (all in KB).

Step 2: Allocate P2 (9 KB).

List the holes that are \(\geq 9\) KB: 20, 25, 9, 15, 12. The smallest among these is exactly 9 KB, so best-fit places P2 into this hole.

Since the hole size exactly equals the process size, \(9 - 9 = 0\) KB remains, so this hole disappears completely (no leftover fragment is created).

Updated hole list: 20, 4, 25, 2, 7, 15, 12 (all in KB) - now only 7 holes remain.

Step 3: Count holes of size less than 8 KB.

From the final list \(\{20, 4, 25, 2, 7, 15, 12\}\), the holes smaller than 8 KB are: 4 KB, 2 KB, and 7 KB.

That gives a count of 3 holes.

Final Answer: \[\boxed{3}\]

Was this answer helpful?
0
0

Top GATE CS Computer Science and IT Engineering Questions

View More Questions