0Pricing
Competitive Programming Academy · Lesson

Prim's MST with a Heap

Grow the tree from one vertex.

A Different Path to the MST

Prim's algorithm also finds a minimum spanning tree, but it grows one connected blob outward instead of sorting all the edges first. 🌱

Grow From One Vertex

Pick any starting vertex and mark it as visited. The tree begins as a single node and expands one edge at a time.

visited = [False] * n

All lessons in this course

  1. DSU with Path Compression
  2. Union by Rank and Components
  3. Kruskal's Minimum Spanning Tree
  4. Prim's MST with a Heap
← Back to Competitive Programming Academy