Question:medium

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: \(1\mathrm{K}=2^{10}\)

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: Aug 3, 2026
Show Solution

Correct Answer: 3

Solution and Explanation

An alternative way to think about this problem is to track only the holes that change, rather than re-listing all of them at every step.

Initial holes (KB): 20, 4, 25, 18, 7, 9, 15, 12. Best-fit always searches for the tightest possible fit so that a process wastes the least amount of leftover space.

Allocating P1 = 16 KB: Among all holes big enough to hold 16 KB (namely 20, 25, 18), the tightest fit is 18 KB because it leaves the smallest leftover (\(18 - 16 = 2\) KB) compared to 20 KB (leftover 4 KB) or 25 KB (leftover 9 KB). So the 18 KB hole is replaced by a 2 KB hole.

Allocating P2 = 9 KB: Among all holes big enough to hold 9 KB (namely 20, 25, 9, 15, 12), the tightest possible fit is the 9 KB hole itself, since it matches exactly and leaves zero leftover. This is the ideal best-fit case - the hole is consumed entirely and vanishes from the hole list.

After both allocations, the surviving holes are: 20, 4, 25, 2, 7, 15, 12 KB (7 holes total, since the original 9 KB hole is gone and the 18 KB hole shrank to 2 KB).

Now filter for holes strictly less than 8 KB: 4 KB, 2 KB and 7 KB qualify, while 20, 25, 15 and 12 KB do not.

So the number of holes smaller than 8 KB is \(3\).

Final Answer: \(3\)

Was this answer helpful?
0


Questions Asked in GATE CS exam