Worst Fit Algorithm in Operating System (OS)

Worst Fit Algorithm in Operating System

The processes need empty memory slots during processing time. This memory is allocated to the processes by the operating system which decides depending on the free memory and the demanded memory by the process in execution.

The three most common memory allocation schemes are first fit, best fit, and worst fit.

Worst Fit algorithm in OS

How Worst Fit Works?

Worst fit works in the following way, for any given process Pn.

The algorithms searches sequentially starting from first memory block and searches for the memory block that fulfills the following condition –

  • Can accommodate the process size
  • Leaves the largest wasted space (fragmentation) after the process is allocated to given memory block
Worst Fit Allocation in OS Working
Worst Fit Allocation in OS Example new 2

Algorithm for Worst Fit Memory Management Scheme

 

  • Step 1: Input memory block with a size.
  • Step 2: Input process with size.
  • Step 3: Initialize by selecting each process to find the maximum block size that can be assigned to the current process.
  • Step 4: If the condition does not fulfill, they leave the process.
  • Step 5: If the condition is not fulfilled, then leave the process and check for the next process.
  • Step 6: Stop.