public class LazyPrimMST extends Object
This implementation uses a lazy version of Prim's algorithm with a binary heap of edges. The constructor takes time proportional to E log E and extra space (not including the graph) proportional to E, where V is the number of vertices and E is the number of edges. Afterwards, the weight() method takes constant time and the edges() method takes time proportional to V.
For additional documentation, see Section 4.4 of
Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
For alternate implementations, see PrimMST, KruskalMST,
and BoruvkaMST.
| Constructor and Description |
|---|
LazyPrimMST(EdgeWeightedGraph G)
Compute a minimum spanning tree (or forest) of an edge-weighted graph.
|
| Modifier and Type | Method and Description |
|---|---|
Iterable<Edge> |
edges()
Returns the edges in a minimum spanning tree (or forest).
|
static void |
main(String[] args)
Unit tests the LazyPrimMST data type.
|
double |
weight()
Returns the sum of the edge weights in a minimum spanning tree (or forest).
|
public LazyPrimMST(EdgeWeightedGraph G)
G - the edge-weighted graphpublic Iterable<Edge> edges()
public double weight()
public static void main(String[] args)
Copyright © 2014. All Rights Reserved.