The Banker's Algorithm:

some definitions:
	- state of a system: 
		the current allocation of M resources to N processes
	- represented by [R, Av, C, Al] = 
		{resources, available, claimed, allocated}
	- claimed and allocated are NxM matrices (processes x resources)
	- safe state: in which there is at least one order of resource granting
  	  so that all processes can be run to completion without deadlock

Now, the algorithm:

	1. alloc' <- allocated

	Loop until termination:

		2. determine total # of available resources of each type:
		   for each resource j, compute:
						    N
			avail[j] <- resources[j] - Sum alloc'[i,j]
						   i=0

		3. find a process i that can be granted its maximum claim:
			for each resource j,
				claimed[i, j] - alloc'[i,j] <= avail[j]

	   	   if no such process exists, UNSAFE (terminate)

		4. pretend that process i is granted its maximum claim, then
	   	   runs to completion and subsequently releases all resources:
		   for each resource j,
			avail[j] <- avail[j] + alloc'[i,j] 
			alloc'[i,j] <- 0

		5. check if all processes have been satisfied:
			?forall i, j: alloc'[i,j] == 0 
			if yes, then SAFE! (terminate)