human
Program for Worst Fit algorithm in Memory Management | Function to allocate memory to blocks as per worst fit algorithm.
Initially no block is assigned to any process.
pick each process and find suitable blocks according to its size ad assign to it.
Find the best fit block for current process.
If we could find a block for current process.
allocate block j to p [ i ] process.
Reduce available memory in this block ..
Driver code"
Solution in Python:
assistant
#Here is code to program for Worst Fit algorithm in Memory Management and the other steps required.
 def worstFit ( blockSize , m , processSize , n ) :
	allocation = [ - 1 ] * n
	for i in range ( n ) :
		wstIdx = - 1
		for j in range ( m ) :
			if blockSize [ j ] >= processSize [ i ] :
				if wstIdx == - 1 :
					wstIdx = j
				elif blockSize [ wstIdx ] < blockSize [ j ] :
					wstIdx = j
		if wstIdx != - 1 :
			allocation [ i ] = wstIdx
			blockSize [ wstIdx ] -= processSize [ i ]
	print ( " Process ▁ No . ▁ Process ▁ Size ▁ Block ▁ no . " )
	for i in range ( n ) :
		print ( i + 1 , " ▁ " , processSize [ i ] , end = " ▁ " )
		if allocation [ i ] != - 1 :
			print ( allocation [ i ] + 1 )
		else :
			print ( " Not ▁ Allocated " )
if __name__ == ' _ _ main _ _ ' :
	blockSize = [ 100 , 500 , 200 , 300 , 600 ]
	processSize = [ 212 , 417 , 112 , 426 ]
	m = len ( blockSize )
	n = len ( processSize )
	worstFit ( blockSize , m , processSize , n )