Graphs

Problem shape

Intermediate
A
B
C
D
E
Core idea

Always expand the currently closest known node using a priority queue.

Step 1 / 5
Problem shape
Current lesson

Dijkstra Shortest Path Lab

Graphs Intermediate

Dijkstra Shortest Path

Welcome to the Dijkstra Shortest Path algorithm lab. Always expand the currently closest known node using a priority queue. Use it when: Use for shortest paths with non-negative edge weights. The time complexity is O((V + E) log V), and the space complexity is O(V). The pseudocode is: dist[start] = 0 push (0, start) while pq not empty d, node = pop min if d is stale continue relax every outgoing edge As you practice, track the state that changes and the condition that makes the algorithm stop.

Time

O((V + E) log V)

Space

O(V)

Pseudocode

dist[start] = 0
push (0, start)
while pq not empty
  d, node = pop min
  if d is stale continue
  relax every outgoing edge
Open deeper structure lesson
1.0x