Lesson 70 of 86AdvancedPro Interactive Lesson

Prim’s Minimum Spanning Tree Algorithm

Consider only edges that cross from the current tree to an outside vertex.

Core Intuition & How It Works

Prim’s algorithm grows a Minimum Spanning Tree outward from a single start vertex, always choosing the lowest-weight edge crossing from the visited tree to an unvisited vertex via a min-heap.

In the Byte Sized Algorithms interactive classroom, you can step forward and backward through this algorithm with your keyboard while watching the visual diagram, memory state, and highlighted pseudocode update together.

Time & Space Complexity

MetricComplexity
Time ComplexityO((V + E) log V)
Space ComplexityO(V + E)
Topic ChapterChapter 12: Shortest Paths & Spanning Trees
Difficulty LevelAdvanced

Key Pattern to Recognize

Unlike Dijkstra (which stores total distance from source), Prim’s priority queue stores only the single connecting edge weight.

Common Pitfalls & Edge Cases

Confusing Prim’s edge-weight key with Dijkstra’s cumulative path-distance key.

Real-World & Technical Interview Applications

Dense graph MST construction, maze generation, and approximating metric Traveling Salesperson tours.

Unlock the full course

All 86 lessons across 15 chapters

View pricing

Delete account

This permanently deletes your account and ends any Pro access.