dijkstra(G, S):
for each node in V:
disance[v] = ∞
distance[S] = 0;
Q = Heap();
while Q is not empty:
v = extractMIN(Q)
for each adjacent u in V:
if distance[u] < distance[v] + w:
distance[u] = distance[u] + w
parent[u] = v
Time Complexity of Dijkstra's algorithm here depends on two things
- To extract minimum from Heap: removing the minimum from Heap takes $O(logn)$ time.
- Update for distance in Heap : each time we update the distance of key we have to check the position of node in Heap and reposition it can $O(logn)$ time
$T(n)$ = $|V| ($remove minimum from Heap$) + deg(|V|)* ($update key$)$
$T(n)$ = $|V| (log|V|) + 2|E|(log|V|)$
$T(n)$ = $ |V|(log|V|) + |E|(log|V|)$
$T(n)$ = $ O((|V|+ |E|) log|V|)$