I know the sequence of step of Dijkstra algorithm is like these:
- Initialize arr
min_distance
, put source as 0, and the others as MAX_VALUE - Pick the min distance that's not in
visited
set - Put vertex to the
visited
set - Loop through all edges linked to the chosen vertex that's not in
visited
set - Update all the min distance
- Keep doing it until we get the destination vertex or no other vertex can be picked
So far I've seen 2 type kind of implementation, one using min heap O(log V) to get the minimum vertex, and the other using simple loop (O(V)).
My question is, if we use min heap, it says the time complexity will be O(E log V), E can be written as V^2. While without it, we can get O(V^2) time complexity. Why does the time complexity seems worse when using min heap?