Okay, suppose There are three processes A, B, C which require 3 blocks of memory,4 blocks, and 6 blocks respectively for execution.
Now the naive solution to ensure that deadlock never occur is to allocate all the demanded blocks before hand but it would cost me 13 blocks of memory.
So optimized method is to allocate A 2 blocks, B 3 blocks, C 5 blocks i.e demand-1. Now why short of 1 only because that way I being resource allocator is aware of the fact that maximum 1 block of memory a process would need at some point of time to complete its execution okay?
Now Suppose after sometime B complete its 3blocks memory part say some calculation or storage and demand for the 1block of memory ,
Here i would allocate it knowing that after this it releases all its blocks because ultimately it completes execution.Now after completion All 4 blocks of memory allocated to B are free and thus it ensures that no deadlock will occur.
And it costs me 5+3+2+1(extra one)=11 blocks of resources