CS502-Fundamentals of Algorithms
Lecture No.34
Lecture No. 34
8.5 Minimum Spanning Trees
A common problem is communications networks and circuit design is that of connecting together a set of nodes by a network of total minimum length. The length is the sum of lengths of connecting wires. Consider, for example, laying cable in a city for cable t.v. The computational problem is called the minimum spanning tree (MST) problem. Formally, we are given a connected, undirected graph G= ( V, E) Each edge (u,v) has numeric weight of cost. We define the cost of a spanning tree T to be the sum of the costs of edges in the spanning tree
w(T) =
(u,v)2T
w(u, v)
A minimum spanning tree is a tree of minimum weight. Figures 8.42, 8.43 and 8.44 show three spanning trees for the same graph. The first is a spanning tree but is not a MST; the other two are.
Figure 8.42: A spanning tree Figure 8.43: A minimum Figure 8.44: Another minithat is not MST spanning tree mum spanning tree We will present two greedy algorithms (Kruskal’s and Prim’s) for computing MST. Recal l that a greedy algorithm is one that builds a solution by repeatedly selecting the cheapest among all options at each stage. Once the choice is made, it is never undone. Before presenting the two algorithms, let us review facts about free trees. A free tree is a tree with no vertex designated as the root vertex. A free tree with n vertices has exactly n- 1 edges. There exists a unique path between any two vertices of a free tree. Adding any edge to a free tree creates a unique cycle. Breaking any edge on this cycle restores the free tree. This is illustrated in Figure 8.45. When the edges (b, e) or (b, d) are added to the free tree, the result is a cycle.
Page 1 © Copyright Virtual University of Pakistan
of 2
CS502-Fundamentals of Algorithms
Lecture No.34
Figure 8.45: Free tree facts
8.5.1 Computing MST: Generic Approach
Let G= ( V, E) be an undirected, connected graph whose edges have numeric weights. The intuition behind greedy MST algorithm is simple: we maintain a subset of edges E of the graph . Call this subset A. Initially, A is empty. We will add edges one at a time until A equals the MST. A subset A E is viable if A is a subset of edges of some MST. An edge (u, v) E- A is safe if A [ {(u, v)} is viable. In other words, the choice (u, v) is a safe choice to add so that A can still be extended to form a MST. Note that if A is viable, it cannot contain a cycle. A generic greedy algorithm operates by repeatedly adding any safe edge to the current spanning tree. When is an edge safe? Consider the theoretical issues behind determining whether an edge is safe or not. Let S be a subset of vertices S V. A cut (S, V- S) is just a partition of vertices into two disjoint subsets. An edge (u, v) crosses the cut if one endpoint is in S and the other is in V-S. Given a subset of edges A, a cut respects A if no edge in A crosses the cut. It is not hard to see why respecting cuts are important to this problem. If we have computed a partial MST and we wish to know which edges can be added that do not induce a cycle in the current MST, any edge that crosses a respecting cut is a possible candidate.
Page 2 © Copyright Virtual University of Pakistan
of 2