Basically, the allocation algorithm is the algorithms with help to allocate the process in the operating system.
So, there are four allocation algorithm:-

  1. First fit
  2. Best fit
  3. Worst fit
  4. Next fit
So, let us talk about each and every allocation algorithm with the help of an example.

1.  First fit

The first fit start searching from starting of the list and it allocates the process to the first free hole
Example:-
ALLOCATION ALGORITHMS
In this algorithm start the search from the starting of the list for a free place or hole to allocate the new process P 1 = 15 K. And when it free a hole it allocate it on the first get hole.
ADVANTAGE OF FIRST FIT

  • It is a faster algorithm because it searches as little as possible.

DISADVANTAGE OF FIRST FIT 



  • This technique suffers from the problem that the remaining/unused memory area left after allocation becomes smaller. Thus request for larger memory requirements can't accommodate.

2.  Best fit

This algorithmic program searches the complete list of free partitions and takes the tiniest hole that's adequate.
OR
It tries to find a hole that is close to the actual process size needed.
EXAMPLE:-
ALLOCATION ALGORITHMS
In the best fit, we choose that free space or hole in which if we allocate a process than the left hole or free space would be as much as less.
So, if we talk about this example than there are two holes are there in the diagram
first is of 20K hole
and second is of 30 K hole
SO,
 left space = hole - P 1

ADVANTAGE OF BEST FIT 

  • Memory utilization is best than the primary match because it searches the tiniest free partition.

DISADVANTAGE OF BEST FIT 

  • It is slower.
  • It may tend to fill up memory with tiny useless holes.

3.  Worst fit

  • Worst fit takes the largest available free portion so that the portion is broken off will be big enough to be useful.
  • It is the reverse of the best fit.
Example:-
ALLOCATION ALGORITHMS

In this, we have to place the process in the biggest hole of the list.

ADVANTAGE OF WORST FIT

  • It is the reverse of the best fit.

DISADVANTAGE OF WORST FIT

  • A process requiring larger memory arriving at a later stage cannot be accommodated as the latest hole is already cannot be accommodated as the largest hole is already split and occupied.

4.  Next fit

The next fit is a modification of the first fit. It begins as the first fit to find a free partition. When called next time it starts searching from where it left off and not from the beginning.

ALLOCATION ALGORITHMS