8.1. Abstraction
This section discusses spanning trees in a graph.
Last updated
This section discusses spanning trees in a graph.
Last updated
©2023 Emory University - All rights reserved
A spanning tree in a graph is a tree that contains all vertices in the graphs as its nodes. A minimum spanning tree is a spanning tree whose sum of all edge weights is the minimum among all the other spanning trees in the graph.
Can a graph have more than one minimum spanning tree?
Let us define the SpanningTree
class under the graph.span
package:
L1
: inherits the Comparable
interface.
L2
: contains all edges in this spanning tree.
L3
: contains the total weight of this spanning tree.
We then define getters and setters:
L3
: the size of the spanning tree is determined by the number of edges.
Finally, we override the compareTo()
method that makes the comparison to another spanning tree by the total weight:
Let us create the interface MST
that is inherited by all minimum spanning tree algorithms:
L2
: an abstract method that takes a graph and returns a minimum spanning tree.