Minimum Spanning Tree - Prim's
Learn Minimum Spanning Tree - Prim's (Graphs, Advanced DSA) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Growing a Minimum Spanning Tree One Vertex at a Time A Minimum Spanning Tree connects ALL vertices with the MINIMUM total edge weight, using exactly V-1 edges and no cycles. Prim's grows the MST from a single starting vertex: repeatedly add the CHEAPEST edge that connects the current tree to a NEW vertex outside it - a min-heap tracks candidate edges efficiently.
More lessons in Graphs
- Graph Representation - Adjacency Matrix
- Graph Representation - Adjacency List
- Directed Graph
- Undirected Graph
- Weighted Graph
- BFS
- DFS
- Connected Components
- Cycle Detection
- Bipartite Graph
- Topological Sort
- Kahn's Algorithm
- DFS Topological Sort
- Shortest Path - BFS
- Shortest Path - Dijkstra
- Shortest Path - Bellman-Ford
- Shortest Path - Floyd-Warshall
- Minimum Spanning Tree - Kruskal's
- Disjoint Set Union - DSU
- Union-Find
- Strongly Connected Components - Kosaraju
- Strongly Connected Components - Tarjan
- Bridges
- Articulation Points
- Euler Path / Circuit
- Hamiltonian Path / Cycle
- Graph Coloring
- Network Flow
- Maximum Flow
- Bipartite Matching