Step by Step Solution of Bankers Algorithm:
By: Prof. (Dr.) Mohit Agarwal (Dept. – CSE – PSIT, Kanpur)
Here I am proving you all the systematic approach of solving the problem based on Banking Algorithm
as discussed in the class as well.
Process Allocation Max Available
ABC ABC ABC
P0 112 433 210
P1 212 322
P2 401 902
P3 020 753
P4 112 123
Step 1: Calculate the Need Matrix
Need = Max – Allocation
Process Allocation (A B C) Max (A B C) Need (A B C)
P0 112 433 321
P1 212 322 110
P2 401 902 501
P3 020 753 733
P4 112 123 011
Step 2: Apply Safety Algorithm
We check if a safe sequence exists.
Initial Work = Available = [2 1 0]
Finish = [F, F, F, F, F]
Check P0
Need = [3 2 1] > Work [2 1 0] → Can't proceed
Check P1
Need = [1 1 0] ≤ Work [2 1 0] → Proceed
→ Work = [2 1 0] + Allocation [2 1 2] = [4 2 2]
→ Finish P1
Work = [4 2 2], Finish = [F, T, F, F, F]
1|Page Prof.(Dr.) Mohit Agarwal
Check P0 again
Need = [3 2 1] ≤ Work [4 2 2] → Proceed
→ Work = [4 2 2] + [1 1 2] = [5 3 4]
→ Finish P0
Work = [5 3 4], Finish = [T, T, F, F, F]
Check P2
Need = [5 0 1] ≤ Work [5 3 4] → Proceed
→ Work = [5 3 4] + [4 0 1] = [9 3 5]
→ Finish P2
Work = [9 3 5], Finish = [T, T, T, F, F]
Check P3
Need = [7 3 3] ≤ Work [9 3 5] → Proceed
→ Work = [9 3 5] + [0 2 0] = [9 5 5]
→ Finish P3
Work = [9 5 5], Finish = [T, T, T, T, F]
Check P4
Need = [0 1 1] ≤ Work [9 5 5] → Proceed
→ Work = [9 5 5] + [1 1 2] = [10 6 7]
→ Finish P4
All processes can finish: System is in a Safe State
Safe Sequence:
P1 → P0 → P2 → P3 → P4
2|Page Prof.(Dr.) Mohit Agarwal