Click or drag to resize
LazyPrimMST Class

The LazyPrimMST class represents a data type for computing a Minimum spanning tree in an edge-weighted graph. The edge weights can be positive, zero, or negative and need not be distinct. If the graph is not connected, it computes a Minimum spanning forest, which is the union of minimum spanning trees in each connected component. The weight() method returns the weight of a minimum spanning tree and the edges() method returns its edges.

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 alternate implementations, see , , and .

Inheritance Hierarchy
SystemObject
  Algs4NetLazyPrimMST

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class LazyPrimMST

The LazyPrimMST type exposes the following members.

Constructors
  NameDescription
Public methodLazyPrimMST
Compute a minimum spanning tree (or forest) of an edge-weighted graph.
Top
Properties
  NameDescription
Public propertyWeight
Returns the sum of the edge weights in a minimum spanning tree (or forest).
Top
Methods
  NameDescription
Public methodEdges
Returns the edges in a minimum spanning tree (or forest).
Public methodStatic memberMainTest
Demo test the LazyPrimMST data type.
Top
Remarks

For additional documentation, see Section 4.3 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

This class is a C# port from the original Java class LazyPrimMST implementation by the respective authors.

See Also