5,204 views
3 votes
3 votes

Time complexity of Multistage Graph is O(n2) or O(V2) but then some people says it's O(E). So, from O(V2) to O(E) are they taking about dense/complete graphs in which number of edges |E| = |V2|?

Kindly help!

2 Answers

Best answer
2 votes
2 votes
In dense graph number of edges are => O(v^2)
thats why we say complexity in worst case will be O(E).
selected by
3 votes
3 votes

In a multi-stage graph algorithm for shortest path, we minimize cost for every edge exactly once. So the Time Complexity is $O(E)$. However, in the worst case, we get a complete graph, which has edges $E = n*(n-1)/2$​, so worst time complexity then becomes $O(E) = O(n^2).$

Note that in this case too, every edge is processed exactly once.

Related questions