1

I am new to Dijkstra Algorithm.

My question is that: for an undirected graph G with n nodes and m edges, the time complexity for Dijkstra Algorithm to find shortestst path is o((n+m)logn). However, if the G is connected, why this time complexity can be also expressed as o(mlogn)?

Cheers

1
  • You've used little-o, but do you mean big theta? Commented Apr 18, 2021 at 7:48

1 Answer 1

1

If it is not connected, say in the case where there is only one edge (m=1), then it can be it is o(nlgn). That is why in the general case it is o((m+n)lgn).

If it is connected, there should be a tree that connects the whole graph (length n-1), so m is at least n-1: (m>=n-1). So for purposes of small O notation (Small O:f is dominated by g asymptotically), I can replace n by m: o((m+1+m)lgn) "=" o(mlgn)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.