Hello friends.welcome to GeeksforGeeks .today

we are going to learn worst fit algorithm for

memory management. What is worst fit.Worst Fit allocates a process

to the partition which is largest sufficient among

the freely available partitions available in the main memory.

Given block sizes and process size we need to find which block is assigned to which process

under worst fit algorithm. This will be Input i.e block_sizes and process

sizes.and your output should be like this Now let’s look at the implementation

1- Input memory blocks and processes with sizes.

2- Initialize all memory blocks as free. 3- Start by picking each process and find

the Maximum block size that can be assigned to

current process i.e., you have to find the maximum of all the blocks that could be assigned

to a process

, if found then assign it to the current process.

5- If not then leave that process and keep checking

the further processes. Block size is 100,500,200,300,600

Processes size is 212,417,112,426 According to the code in the article we will

see how this example proceeds. N is number of processes which is 4 and m

is number of available blocks which are 5.let allocation be an array of size 4 and initialized

with all -1. i=0 process size=212,

Block with size 500,300,600 can be allocated to this process maximum among them is 600

so worst fit block size would be 600 so allocation[0]=4

which is the index of the block 600 blocksize=600-212=388

Now this block has space 388 i=1 process size=417,worst fit=500 so allocation[1]

becomes 1 blocksize-=417 which is 83. Now available block sizes are 100 83 200 300

388 When i=2 process size=112,so 200,300,388 can

be allocated to this process but maximum among them is 388 so worst fit block size=388

so allocation[2]=4 block size[4]-=112 so which is

276 Now this block has space 276 when i=3 process

size[3]=426,here no block is greater than or

equal to 426 worst fit not available so allocation[3] remains -1

At last allocation array will be like this 4 1 4 -1 and the output should be this.

Thanks for watching this video i hope you like this.please leave us your likes and comments