Data structure in the Banker’s algorithm

Q.2) Consider the following system snapshot using data structure in the Banker’s algorithm, with resource A,B,C,D and Process P0 to P4.



a.)Is the system is safe state?

b.) If a request from process P4 arrived for additional resources of (1,2,0,0) can Banker’s Algorithm grant the request immediately? Show the new system state and other criteria.

Ans. a.)

For solving the above problem using Banker’s algorithm we will use two array name as work and finish.

Work: It is a one dimensional array that keeps tracks of current available resources of all the process.

Finish: It is a one dimensional array that keeps tracks of logically finished process.

Next we will find out the Need array as follows.

Max – Allocation=Need.



Initialize the array Finish and Work as follows and apply safety algorithm.
Finish = {False, False, False, False, False};
Work = {3, 2, 1, 1};

Is Need of P0 <= Work => {2, 0, 1, 1} <= {3, 2, 1, 1} =>True
So Finish= {True, False, False, False, False};
Work = {3, 2, 1, 1}+{4,0,0,1}(Allocation of P0)= {7,2,1,2}
Safe Sequence= {P0}

Is Need of P1 <= Work => {0,6,5,0} <= {7, 2, 1, 2} => False
So Finish= {True, False, False, False, False};

Is Need of P2 <= Work => {1, 1, 0, 2} <= {7, 2, 1, 2} =>True
So Finish= {True, False, True, False, False};
Work = {7, 2, 1, 2}+{1, 2, 5, 4}(Allocation of P2) = {8,4,6,6}
Safe Sequence= {P0, P2}

Is Need of P3 <= Work => {1, 0, 2, 0} <= {8,4,6,6} =>True
So Finish = {True, False, True, True, False};
Work = {8,4,6,6}+{0, 6, 3, 3}(Allocation of P3)= {8,10, 9, 9}
Safe Sequence= {P0,P2,P3}

Is Need of P4 <= Work => {1, 4, 4, 4} <= {8,10, 9, 9} =>True
So Finish = {True, False, True, True, True};
Work = {8,10, 9, 9}+{0, 2, 1, 2}(Allocation of P4)= {8,12,10,11}
Safe Sequence= {P0,P2,P3,P4}

Is Need of P1<= Work => {0,6,5,0} <= {8,12,10,11}} =>True
So Finish= {True, True, True, True, True};
Work = {8,12,10,11}}+{1,1,0,0}(Allocation of P1)= {9,13,10,11}
Safe Sequence= {P0,P2,P3,P4,P1}

Yes System is in safe state.
Post your comment

    Discussion

  • RE: Data structure in the Banker’s algorithm -M vignesh (09/29/21)
  • Sir i need answer for 2b
  • RE: Data structure in the Banker’s algorithm -M vignesh (09/29/21)
  • Sir i need answer for 2b
  • RE: Data structure in the Banker’s algorithm -M vignesh (09/29/21)
  • Sir i need answer for 2b
  • RE: Data structure in the Banker’s algorithm -Priyanka somanahalli (06/26/18)
  • Pls ans for 2.b ....
  • RE: Data structure in the Banker’s algorithm -KEFAH (08/03/16)
  • NICE ELABORATION!