Banker’s Algorithm
1. Aim
To obtain a deadlock-free process mix and simulate Banker’s Algorithm to determine whether the system is in a safe state and to find a safe execution sequence.

2. Objectives
To understand the concept of deadlock avoidance

To apply Banker’s Algorithm

To determine whether a system is in a safe or unsafe state

To find a safe sequence of processes

3. Theory
Deadlock
A deadlock occurs when a set of processes are blocked forever, each waiting for resources held by others.

Deadlock Avoidance
Deadlock avoidance ensures that the system never enters an unsafe state.
The Banker’s Algorithm is a classic deadlock avoidance algorithm.

Banker’s Algorithm
The algorithm checks for system safety by simulating resource allocation and ensuring that:

There exists a safe sequence

Each process can finish execution with available resources

If such a sequence exists → Safe State
Otherwise → Unsafe State

4. Data Structures Used
Structure	Description
Available	                    Currently available resources
Max	                    Maximum resources required by each process
Allocation	                    Resources currently allocated
Need	                    Remaining resource requirement (Max - Allocation)
5. Given Process Mix (Deadlock-Free Example)
Number of Processes: 5 (P0 – P4)
Number of Resource Types: 3 (A, B, C)
Allocation Matrix
Process	    A	B	C
P0	    0	1	0
P1	    2	0	0
P2	    3	0	2
P3	    2	1	1
P4	    0	0	2
Maximum Requirement Matrix
Process	    A	B	C
P0	    7	5	3
P1	    3	2	2
P2	    9	0	2
P3	    2	2	2
P4	    4	3	3
Available Resources
Available = [3, 3, 2]
6. Need Matrix Calculation
Need = Max – Allocation
Process	    A	B	C
P0	    7	4	3
P1	    1	2	2
P2	    6	0	0
P3	    0	1	1
P4	    4	3	1
7. Banker’s Algorithm (Safety Algorithm)
Algorithm Steps
