1 / 39

Spanning Trees & Kruskal’s Algorithm

Spanning Trees & Kruskal’s Algorithm. Notes 2 - Sections 7.2 & 7.3. Essential Learnings. Students will understand and be able to create spanning trees. Students will understand and be able to use Kruskal’s Algorithm. Reformulate Property 3 to. PROPERTY 4.

tyrell
Download Presentation

Spanning Trees & Kruskal’s Algorithm

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Spanning Trees & Kruskal’s Algorithm Notes 2 - Sections 7.2 & 7.3

  2. Essential Learnings • Students will understand and be able to create spanning trees. • Students will understand and be able to use Kruskal’s Algorithm.

  3. Reformulate Property 3 to . . . PROPERTY 4 ■If a network has N vertices and M edges, then M ≥ N – 1.For convenience, we will refer to the difference R = M – (N – 1)as the redundancyof the network. ■If M = N – 1, the network is a tree; if M> N – 1,the network has circuits and is not a tree. In other words, a tree is a network with zero redundancy, and a network with positive redundancy is not a tree.

  4. Spanning Trees In the case of a network with positive redundancy, there are many treeswithin the network that connect its vertices–these are the spanning trees of thenetwork.

  5. Example – Counting Spanning Trees The network in the figure has N = 8vertices and M = 8 edges. The redundancyof the network is: R= M – (N – 1)= 1, so to find a spanning tree we will have to“discard” one edge.

  6. Example – Counting Spanning Trees Five of these edges are bridges of the network, and they willhave to be part of any spanning tree. The other three edges (BC, CG, and GB) forma circuit of length 3, and if we exclude any one of the three edges, then we will havea spanning tree.

  7. Example – Counting Spanning Trees Thus, the network has three different spanning trees.

  8. Example – Counting Spanning Trees The network in the Figure has M = 9 edges and N = 8 vertices. The redundancy of the network is R = 2,so to find a spanning tree we will have to “discard” two edges. Edges AB and AH are bridges of the network, so they will have to bepart of any spanning tree.

  9. Example – Counting Spanning Trees The other seven edges are split into two separate circuits(B, C, G, B of length 3 and C, D, E, F, C of length 4). A spanning tree can be foundby “busting” each of the two circuits. This means excluding any one of the threeedges of circuit B, C, G, B and any one of the four edges of circuit C, D, E, F, C.

  10. Example – Counting Spanning Trees Forexample, if we exclude BC and CD, we get the spanning tree shown.

  11. Example – Counting Spanning Trees We could also exclude BC and DE and get the spanning tree shown.

  12. Example – Counting Spanning Trees Given that there are 3  4 = 12different ways to choose an edge fromthe circuit of length 3 and an edge from the circuit of length 4, there are 12 spanning trees. We have already shown two, here’s one more.

  13. Example – Counting Spanning Trees This network has M = 9 edges and N = 8 vertices. Here the circuits B, C, G, B and C, D, E, G, C share a common edge CG. Determiningwhich pairs of edges can be excluded in this case is a bit more complicated.

  14. Example – Minimum Spanning Trees This example builds on the ideas introduced in Example 7.2. The network shownin is the same network as Example 7.2 now with weights added tothe edges.

  15. Example – Minimum Spanning Trees Vertices represent computer labs, and edges are potential Ethernet connections. The weights represent the cost in K’s (1K = $1000) of installing the Ethernet connections.

  16. Example – Minimum Spanning Trees Using the terminology we introduced in this section, the weighted network has a redundancy of R= 3(the network hasM = 14vertices andN = 12edges).

  17. Example – Minimum Spanning Trees The network has many possible spanning trees, and our job is to find one with least weight, that is, a minimum spanning tree (MST) for the network. We can find a spanning tree byexcluding certain edges of the network (those that close circuits) from the spanning tree and that there are many different ways in which this can be done.

  18. Example – Minimum Spanning Trees Giventhat the edges now have weights, a reasonable strategy for sorting through theoptions would be to always try to exclude from the network the most expensive edges.

  19. Example – Minimum Spanning Trees To illustrate the point, let’s look at circuit B, C, D, E, B on the left side of the network. It makes sense to exclude CD(which costs $95,000 to build).

  20. Example – Minimum Spanning Trees Likewise, on the right side of the network wehave a configuration of two circuits K, H, I, Kand K,J,I,K that share the common edgeKI.

  21. Example – Minimum Spanning Trees We exclude the two most expensive edges from these two circuits (KJand KI).

  22. Example – Minimum Spanning Trees At this point, all the circuits of theoriginal network are “busted,” and we endup with the red spanning tree shown.

  23. Minimum Spanning Trees Is the red spanning tree obtained in the previous example the MST of the originalnetwork? We would like to think it is, but how can we be sure, especially after thelessons learned in Chapter 6? And even if it is, what assurances do we have that oursimple strategy will work in more complicated graphs? These are the questionswe will answer next.

  24. Kruskal’s Algorithm

  25. Kruskal’s Algorithm Kruskal’s algorithm is almost identical to the cheapest-linkalgorithm: • We build the minimum spanning tree one edgeat a time, choosing at each step the cheapest available edge.

  26. Kruskal’s Algorithm • The only restriction toour choice of edges is that we should never choose an edge that creates a circuit.Having three or more edges coming out of a vertex, however, is now OK. • Whatis truly remarkable about Kruskal’s algorithm is that–unlike the cheapest-link algorithm–it always gives an optimal solution.

  27. Example – The Amazonian Cable Network: Part 2 What is the optimal fiber-opticcable network connecting the seven towns shown?

  28. Example – The Amazonian Cable Network: Part 2 The weightedgraph shows the costs (in millions of dollars) of laying the cablelines along each of the potential links of the network.

  29. Example – The Amazonian Cable Network: Part 2 The answer, as we now know, is to find the MST of the graph. We will use Kruskal’s algorithm to do it. Here are the details:

  30. Example – The Amazonian Cable Network: Part 2 Step 1.Among all the possible links, we choose the cheapest one, in this particular case GF (at a cost of $42 million). This link is going to be part of the MST,and we mark it in red (or any other color) as shown

  31. Example – The Amazonian Cable Network: Part 2 Step 2.The next cheapest link available is BD at $45 million. We choose it forthe MST and mark it in red. Step 3.The next cheapest link available is AD at $49 million. Again, wechoose it for the MST and mark it in red.

  32. Example – The Amazonian Cable Network: Part 2 Step 4.For the next cheapest link there is a tie between AB and DG, both at$51 million. But we can rule out AB–it would create a circuit in the MST,and we can’t have that! The link DG, on the other hand, is just fine, so we markit in red and make it part of the MST.

  33. Example – The Amazonian Cable Network: Part 2 Step 5.The next cheapest link available is CD at $53 million. No problemshere,so again, we mark it in red and make it part of the MST.

  34. Example – The Amazonian Cable Network: Part 2 Step 6.The next cheapest link available is BC at $55 million, but this linkwould create a circuit, so we cross it out. The next possible choice is CF at $56million, but once again, this choice creates a circuit so we must cross it out.The next possible choice is CE at $59 million, and this is one we do choose.We mark it in red and make it part of the MST.

  35. Example – The Amazonian Cable Network: Part 2 Step ...Wait a second–we are finished! Even without looking at a picture,we can tell we are done–six links is exactly what is needed for an MST onseven vertices. The figure shows the MST in red. The total cost of the network is$299 million.

  36. KRUSKAL’S ALGORITHM Step 1:Pick the cheapest link available. (In case of a tie, pick one at random.)Mark it (say in red). Step 2:Pick the next cheapest link available and mark it. Steps 3, 4, ..., N–1:Continue picking and marking the cheapest unmarkedlink available that does not create a circuit.

  37. Kruskal’s Algorithm As algorithms go, Kruskal’s algorithm is as good as it gets. First, it is easy toimplement. Second, it is an efficient algorithm. As we increase the number of vertices and edges of the network, the amount of work grows more or less proportionally. If finding the MST of a 30 - city network takes you, say,30 minutes, finding the MST of a 60 - city network might take you 60 minutes.

  38. Kruskal’s Algorithm Last, but not least, Kruskal’s algorithm is an optimalalgorithm–it will alwaysfind a minimum spanning tree. Thus, we have reached a surprisingly satisfying end to the MST story: Nomatter how complicated the network, we can find its minimum spanning tree bymeans of an algorithm that is easy to understand and implement, is efficient, andis also optimal.

  39. Assignment p. 266: 11, 13, 15, 17, 19, 21, 24, 25, 39, 51 Writing Assignment 1 – Topics from Sections 7.1 – 7.3: Due Tuesday Quiz – Monday Make a note card

More Related