Foundations
Linear Structures
Hashing
Array and String Patterns
Recursion, Search, and Sorting
Problem Solving Patterns
Algorithm Searching
Sorting Algorithms
Array Algorithms
Grid Algorithms
Linear Structure Algorithms
Hashing Algorithms
Recursion and Backtracking
Greedy Algorithms
Tree and Heap Algorithms
Graph Algorithms
Dynamic Programming Algorithms
String Algorithms
Math Algorithms
Keyboard ready
Space plays. Arrow keys step. R restarts.
LAB Dijkstra Shortest Path Lab
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
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 1.0x