edited by
834 views
0 votes
0 votes
given a graph G,a matrix Pk represent  a matrix in which each entry pk[i][j]   represent  the shortest path from node i to node j in G which uses only nodes 1,2,3.............k-1 .The corresponding graph formed by using matrix Pk[i][j] is termed as Gk .

Gk can be calculated by taking the square of  adjacency matrix of  G k times and replacing each multiplication and addittion operation by AND and OR operation.(concept of warshall's algorithm of unweighted graph) .now my question is how to find Gk if the graph G is represented by using  adjacency list and what will be the time complexity to do it ??
edited by

1 Answer

0 votes
0 votes

what i think is O(v^4) may be the answer. 
first of all the data is in adhency list like this

to compute inital distances time taken will be o(v3) as suppose i am calculating a then for the idstnce to b i have to seach all the adjency nodes of a . which may be v in worst case. and for c again and so v time i have to search v nodes which is v2 and i have to do so for v times . so v3. now when i have calculated the initial matrix distances. and such v matrix have to be calculated . else u may think this way .

now for distance of a to c through b we will hav to first find the distance from a to b which is v time and then from b to c which is also v time now . and then compare with the inital distances . so time complexity will be (v+V+1)=O(v) this is just one entry . such v^2 nodes have to calculated in worst case i.e. complete graph . and such v passes will be made so v*v^2*v=O(V^4).

answer may be wrong . what is the answer.

Related questions

3 votes
3 votes
2 answers
1
dd asked Dec 6, 2016
2,642 views
Let P be a shortest path from some vertex s to some other vertex t in a directed graph. If the weight of each edge in the graph is increased by one, P will still be a sho...
2 votes
2 votes
1 answer
3
Sahil Gupta asked Dec 16, 2014
659 views
if Dijkstra shorest path algorithm takes 8 second for a graph of 1000 nodes then approximatly how much time would it take for a graph of 1000000 nodes.a) 8000000 sec.b) 8...