Graph Theory37 sections · 1633 units
Open in Course

Algorithm - Prim on Implicit Graph

(Compute edges as needed)

Prim's algorithm works well here because you do not need to generate all edges upfront. Start with one point. At each step, find the nearest unvisited point and add it to the MST. Use a priority queue to track distances from the current MST to all unvisited points. Update distances as you add points.

This approach uses O(n)O(n) space instead of O(n2)O(n^2) for storing edges. The time complexity is O(n2logn)O(n^2 \log n) with a binary heap.