Prim’s Algorithm

Grows MST from a seed node, always adding the cheapest edge to the outside.

Method

Priority queue of frontier edges; add min edge.

Applications

Same as Kruskal; often faster on dense graphs.

Advantages

Two greedy views of the same optimum.

Limitations

O(E log V) with heap; dense graphs can use O(V^2). Repeatedly select a minimum-weight crossing edge. Runtime depends on implementation: eager binary-heap Prim O(E log V), lazy Prim O(E log E).

Example

Same city problem: start at city A, greedily attach nearest unconnected city.

Editorial clarification

Repeatedly select a minimum-weight crossing edge. Runtime depends on implementation: eager binary-heap Prim O(E log V), lazy Prim O(E log E).

Sources

Educational reference only, not professional advice.

All algorithms