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 Prim MST Lab
Graphs
Problem shape
Intermediate
A
B
C
D
E
Core idea
Grow a tree by repeatedly adding the cheapest edge leaving the current tree.
Step 1 / 5
Problem shape
Graphs Intermediate
Prim MST
Welcome to the Prim MST algorithm lab. Grow a tree by repeatedly adding the cheapest edge leaving the current tree. Use it when: Use for minimum spanning tree with adjacency lists and priority queues. The time complexity is O(E log V), and the space complexity is O(V). The pseudocode is: start from any node push outgoing edges while tree incomplete take cheapest edge to unseen node add node and its outgoing edges As you practice, track the state that changes and the condition that makes the algorithm stop.
Time
O(E log V)
Space
O(V)
Pseudocode
start from any node
push outgoing edges
while tree incomplete
take cheapest edge to unseen node
add node and its outgoing edges 1.0x