The Banker's algorithm is used to determine if all requests for resources can be satisfied without leading to a deadlock.
m is the total number of resources types
n is the total number of processes
NEED is an array of size m * n, it defines pending requests for each resources type. E.g.: NEEDij = 2 means that process i is requesting for 2 items of resource j.
The algorithm is given below:
BOOLEAN function SAFESTATE is -- Determines if current state is safe
{ NOCHANGE : boolean;
WORK : array[1..m] of INTEGER = AVAILABLE;
FINISH : array[1..n] of boolean = [false, ..,false];
I : integer;
repeat
NOCHANGE = TRUE;
for I = 1 to N do
if ((not FINISH[i]) and
NEEDi <= WORK) then {
WORK = WORK + ALLOCATION_i;
FINISH[i] = true;
NOCHANGE = false;
}
until NOCHANGE;
return (FINISH == (true, .., true));
}
My question is, how is time complexity 0(n * n * m)? More specifically, how does the m term enter the polynomial? Is it because we have to do an element-by-element comparison on a vector of length m?