edited by
1,001 views
1 votes
1 votes

 

Here each resource have a single instance, we can check whether a given system is safe or not is by checking whether there exists a cycle or not, To detect cycle in the graph, the most efficient algorithm is the DFS, So, Time complexity should be O(m+n), assumed number of edges approximately equals to the number of vertices.
But the answer given is O(m*n^2).
Can anyone explain how O(m*n^2)? 

edited by

1 Answer

1 votes
1 votes
let suppose the process are

1 2 3 4 5 6 7 8 9…………………………..n

each process required m resource. we know that for getting safe sequence we need to 1 less then total resource so required resources are

process                  (   1           2              3               4                5               6 ………………….n          )

 

resource needed  (  m-1       m-1            m-1          m-1             m-1         m-1 ………………….m-1    )

 

now total resource are  1*(m-1) + 2(m-1)……………….………..n(m-1)

 

for deadlock free  or safe sequence  n(m-1)+1

                                                           nm-n+1

 

hence O(N*M)  time is required

Related questions

0 votes
0 votes
0 answers
1
SKMAKM asked Oct 22, 2022
429 views
Answer -3.7
0 votes
0 votes
0 answers
2
SKMAKM asked Oct 20, 2022
528 views
Answer 3.12
0 votes
0 votes
2 answers
3
Crackca asked Nov 28, 2021
528 views
How to calculate the sizeof(arr2)?
1 votes
1 votes
2 answers
4