类 KruskalMST


  • public class KruskalMST
    extends java.lang.Object
    The KruskalMST 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 Krusal's algorithm and the union-find data type. The constructor takes time proportional to E log E and extra space (not including the graph) proportional to V, 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.3 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne. For alternate implementations, see LazyPrimMST, PrimMST, and BoruvkaMST.

    • 构造器概要

      构造器 
      构造器 说明
      KruskalMST​(EdgeWeightedGraph G)
      Compute a minimum spanning tree (or forest) of an edge-weighted graph.
    • 方法概要

      修饰符和类型 方法 说明
      java.lang.Iterable<Edge> edges()
      Returns the edges in a minimum spanning tree (or forest).
      static void main​(java.lang.String[] args)
      Unit tests the KruskalMST data type.
      double weight()
      Returns the sum of the edge weights in a minimum spanning tree (or forest).
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 构造器详细资料

      • KruskalMST

        public KruskalMST​(EdgeWeightedGraph G)
        Compute a minimum spanning tree (or forest) of an edge-weighted graph.
        参数:
        G - the edge-weighted graph
    • 方法详细资料

      • edges

        public java.lang.Iterable<Edge> edges()
        Returns the edges in a minimum spanning tree (or forest).
        返回:
        the edges in a minimum spanning tree (or forest) as an iterable of edges
      • weight

        public double weight()
        Returns the sum of the edge weights in a minimum spanning tree (or forest).
        返回:
        the sum of the edge weights in a minimum spanning tree (or forest)
      • main

        public static void main​(java.lang.String[] args)
        Unit tests the KruskalMST data type.
        参数:
        args - the command-line arguments