FOR FREE CONTENT

Best Fit and Worst Fit

 

3) Best Fit 

Allocate the smallest hole that is big enough. We must search the entire holes unless the list is ordered by size. It chooses the smallest hole possible and it allocates the process.

The best-fit allocation method keeps the free/busy lists in order by size, smallest to largest.

 

Example for the Best Fit

Now a process P4 of size 15 MB  tries to allocate at the memory. So, as per the best-fit algorithm, it chooses the smallest one possible, so, it chooses a hole with a size 20 MB for process P4, whereas if we think about the first fit, it will choose Hole-40 MB for process P4.

 

 

Advantage of Best Fit

It tries to reduce the wastage of space because it allocated the smallest appropriate holes for requesting process. 

 

Disadvantage of Best Fit

i)  It requires O(n) time to search the entire list and find the smallest one.

 

ii)  As if it chooses the smallest possible space, so, the very small size of hole is free and not fit farther for any process, it will wastage at the above the best-fit example, at best for P4 process allocated space is hole-18 MB, so, after allocated P2, the new hole is 2 MB and it too small to allocate any process at future, so, it is wastage.

 

 

So, sometimes best fit is not an efficient one.  But in the case of the first fit, P2 allocated it H-40 MB, so, after allocated P2, the free hole will be 22 MB, it will good hole for a size

 

4) Worst fit 

Allocate the largest hole. Again, we must search the entire list, unless it is sorted by size. In case of worst fit, unlike the best fit, it searches the entire hole and chooses the largest hole possible, and allocates the process.

 

The best-fit allocation method keeps the free/busy lists in order by size, largest to smallest.

 

Here it requires O(n) time like the best fit to search the entire list and find the largest one. But one advantage is there compare to best firstafter allocating process as per worst fit free holes size is large and it is useful to allocate other processes.

 

Hereafter allocating free hole size is large i.e. better but still, it requires O(n) to search the entire hole.