The key point to be followed in solving this type of question is :
We select a process such that its need (demand) is satisfied by the currently available resources.
For this question hence we need to calculate the need matrix first which is given by :
Need[i][j] = Maximum[i][j] - Allocation[i][j] .So need matrix is given by :
A B C
7 4 3
1 2 2
6 0 0
0 1 1
4 3 1
Having calculated the need matrix in order to find no of safe sequences , we need to do it carefully as by partly taking cases and partly applying combinatorics keeping in mind the requirements of safety algorithm.
We have to select a process such that the need of every resource of that process <= the available resource at that instant
So initially we have only P1 and P3 satisfying the given constraint.Hence we solve them separately :
Case 1(P3 is selected first) :
Now if P3 is selected first , then available is updated as :
available[j] = available[j] + allocation[3][j] where j varies from 1 to 3 since after usage a process needs to free its allocated resources , hence we are adding it to the available number of resources of each type.
So available = [3 3 2] + [2 1 1] = [ 5 4 3]
Now considering the condition need[i][j] <= available[j] for the next process to be selected , we have only 2 such process after P3 i.e. P1 and P4
Proceeding with P1 , meaning let P1 is selected after P3 , so available is now updated as :
[5 4 3] + [2 0 0] = [7 4 3]
Now we can see that we do not need to proceed further since the need of any of the 3 remaining will be satisfied from this point.At this point any of the 3 processes can be selected , after 3rd process is executed the available resources will further increase , so not a problem.
Hence no of ways from this instant if we take P1 after P3 = 3! = 6
If we consider choosing P4 after P3 , then after updation of available resources , only P1 satisfies so P1 has to be selected and after P1 , either P0 or P2 can come.
So no of ways here = 2
Hence , for a) part i.e. beginning with P3 , no of safe sequences = 6 + 2 = 8
For part b) also i.e. safe sequence beginning with P1 , we will have 6 cases if we have P3 after P1 and 2 cases if we have P4 after P1 .
So no of sequences here = 8 as well
Hence total no of safe sequences = 8 + 8
= 16
Hence 16 is the correct answer.