Address
:
[go:
up one dir
,
main page
]
Include Form
Remove Scripts
Session Cookies
Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
97 views
16 pages
Minimum Spanning Tree
Uploaded by
Aryan Neelam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save Minimum Spanning Tree For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
97 views
16 pages
Minimum Spanning Tree
Uploaded by
Aryan Neelam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save Minimum Spanning Tree For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 16
Search
Fullscreen
22.1. INTRODUCTION et The sta seation of minimum spanning tree is to solve a problem like phone network Deiat never bosinses with several offices; we want to lease phone lines to cone them up with each other; and the phone company charges jiffere: icttoad tine. ey connect different pairs of cities. We want a set of lines that connects ofc with coe rmum total cost, It should be a minimum spanning tree, since if a network is't a tree we can always remove some edges and save money. We can model this phone network problem with a connected, undirected graph G = (V, B), where Vis the set of cities, and is the set of possible interconnections between pairs of cities, and for each edge, we have a weight w specifying cost or the amount of wire needed to connect two cities, We then wish, to find an acyclic subset T < E that connects alll of the vertices and whose total weight is minimized. w(T) = w(u,v) ee 22.2. SPANNING TREES A spanning tree of a graph is any tree that includes every vertex in the graph. More formally, a spanning tree of a graph G is a subgraph of G that is a tree and contains all the vertices of G. We construct spanning tree whenever we want to find a simple, cheap and efficient way to connect a set of terminals (computers, cities, factories, etc). Spanning trees are important because of following reasons. * Spanning trees construct a sparse sub graph that tells a lot about the original graph. * Spanning trees are very important in designing efficient routing algorithms. . Some hard problems (e.g., Steiner tree problem and travelling salesman problem) ca” ¢ solved approximately by using spanning trees, oles pace a : ‘nning trees have wide applications in many areas, such as network design, ete: imum s] i et OM) sone ; ini spanning tree aa ae free (MST) is a spanning tree of minimum weight, The minimu® nique, but it is true if all the edge weights are distinct. } 438linimum Spanning Tree she following is an example of spanning and minimum spanning tr ee, — ‘Agraph G ‘Thee (ofthe many possible) spanning {trees from graph (Gy 2 2 ; XI oie ay O 7 O 1 ‘Aveighted graph (G) The minimum spanning ‘tree from weighted graph G Fig. 22.1. There are two algorithms: The Kruskal’s algorithm and the prim’s algorithm to find the ninimum spanning tree of an undirected weighted graph. These algorithms use similar approaches, but works in very different ways. 22.3. KRUSKAL’S ALGORITHM FOR MST Kruskal’s algorithm is a greedy algorithm. A greedy algorithm chooses some local optimum (ie, picking an edge with the least weight in a MST). It builds the MST:in forest. Initially, each vertex is in its own tree in forest. Then, algorithm considers each edge in turn, ordered by increasing weight. Ifan edge (wu, v) connécts two different trees then (u, v) is added to the set of edges of the MST, and two trees connected by an edge (u, v) are merged into a single tree on the other hand, if an edge (w, v) connects two vertices in the same tree, then edge (u, »)is discarded. ‘Therefore is Start with an empty set A, and select at every stage the smallest edge that has not been chosen or rejected, regardless of where this edge is situated in graph. Kruskal’s algorithm uses a disjoint-set data structure to maintain several disjoint sets of elements, Digjoint-Sets Data Structure: * Make-Set (x): Create a new set whose only member is pointed to by v. Note that for this operation v must already be in a set. * FIND-SET; Returns a pointer to the set containing v. * UNION (uw, v): Units the dynamic sets that contain u and v into anew set that is union of these two sets, | MST-KRUSKAL (6, w) ph Aco= Design and Analysis of Algorithms ™ x mo \_— for each vertex V & vicl do MAKE-SET(V) f sort the edges of E into nol : for each edge (Ur v) € E, taken in nondecreaing 2. i n decreasing order by weight w 4, 5. 6, dof FIND-SET(u) # FIND-SET (v) 7. 8 9. order by weight then Ac AU {(u, VT : UNION(U, v) . return A Analysis: Let V be the number of vertices and E be the number of edges and we assume that E> V-1 It takes © (E log £) time to sort the edges. The for loop iterates E number of times, and each iteration involves a constant number of accessed to the Union-Find disjoint set data structure on the collection of V items. Thus each access takes @(V) time, which gives a total of @ (E log V) times. ‘Thus the total running time for the algo is @((V + E) log V). Since V is not asympto' expressed as © (E log V). rithm is evaluated by adding up all these, which tically larger than E, the running time can be Problems With Kruskal: + Kruskal’s algorithm grows a series of trees which are disjoint. © Growing a set of disjoint trees may be a problem in some applications. * Kruskal also continues checking edges even when all nodes are inserted. * Checking the edges can be inefficient in that a graph can have up V? edges. * Many of these edges will be creating cycles. EXAMPLE 22.1. Using Kruskal’s algorithm find the minimum spanning tree of the following given graph. = Fig. 22.2. ‘olution: Step 1: Initialize the set A to empty set Az=6Minimum Spanning Tree step 2: Create |V| trees one for each verted by using MAKE-SET - procedure {€1}, (2, {3}, (4), 5), (8 Step 3: Sort the edges of E into non-decreasing order by weight (4,3) =2 (4,6) =3 (2,5) =4 (3,6) =5 (1,4) =6 (2,8) =6 (3, 4) =6 (3,5) =7 (5,6) =7 (1,2) =7 Step 4: Select at every stage the smallest edge that has been chosen or rejected, regardless of where this edge is situated in graph. Now we choose (1, 3) ® | o ) © {(1, 3), (2), {4}, (5), (6) Now we choose (4, 6)‘= Design and Analysis of Algorithms = © a 3 © © {(1, 3}. (2), (4, 6) (5 pag {1,3}, (2, 5}, 4, OF Now we choose (2, 5) Now we choose (3, 6) {(1 3, 4, 6} {2, 5} Now we choose (2, 3) {(1, 2, 3, 4, 5, 6} therefore, weight of MST is 243 + 4+5+6=20= Minimum Spanning Tree = EXAMPLE 22.2. Find the MST of the following given graph using Kruskals algorithm. Fig. 22.3. Solution: Step 1 : Initialize the set A to empty set A = Step 2: Create |V| trees one for each vertex by using MAKE-SET procedure QO” © © © © {{a}, {b}, {c}, {a}, fe}, {9 Step 3 : Sort the edges of E into non-decreasing order by weight. (a,d) = ff) = (e, e) (d, e) (c, d) (df) = (a, c) (a,b) = 12 (b,c) = 14 ae 4: Select at every stage the smallest edge that has not been choosen or rejectes ss of where this edge is situated in graph. " " ae ROD me= Design and Analysis of Algorithms = We choose (a, d) 1 © ete © {{a, dh, {b}, {} {2} (9) Now we choose (e, f) O-+-O {fa,d}, {b}, {c} {e, }} Next we choose (c, e) Next we choose (e, d)Minimum Spanning Tree 445 Front we enoose (aD) 2 © fore weight of MST is 12+1+2+8+1=19. fa.b,c,d,e,f} ‘There! GORITHM FOR MST ‘m is another greedy algorithm for minimum spanning trees. It differs from Kruskal’s algorithm only in how it selects the next safe edge to add at each step. The main jdea of Prim’s algorithm is similar to that of Dijkstra’s algorithm for finding shortest path jnagiven graph. Prim's algorithm has the property that the edges in the set that always form a single tree. We begin with some vertex u in a given graph G = (V, EB), defining the al set of vertices A. Then, it each iteration, we choose a minimum weight edge (u, v), init A to the vertex v outside of set A. Then vertex v is brought tonnecting a vertex u in the set jatoA. This process is repeated ‘until a spanning tree is formed. Like Kruskal’s algorithm, the important fact about MST is that we always choose the smallest-weight edge joining a vertex inside set A to the one outside the set A. Prim’s is slightly more efficient than Kruskal. m4. PRIM'S: jn’s algorith MST-PRIM (G, W, T) 1, foreach ue VIG] 2. dokey [uJ = 3. fu] — NIL 4. key [r] 0 5. Qe VIG] 6. whileQ+o 7. dou EXTRACT-MIN (Q) 8. for each v « Adj[u] 8 do if v ¢ Qand w(u, v) < key Lv] 10. then x[v] cu LM keyv] < w(u, v) How it works: oe the tree * The prim’s algorithm starts with an arbitrary root vertex rand grows Spans all the vertices in V. * Initialize the root vertex with key 0 and other vertices queue s with key . Pe ee key. The initial step is to put all vertices onto a priority Cae * The source vertex has 0 as its key, 60 it is choosen first and its adjace for the smallest weight edge which is added to the tree. list exploredas \ Ms = Design and Analysis of Algorithms = * Atall times the smallest weight edge between included in the tree is added. * This process continues until all vertices are removed from the priority quoug, “he included vertices and the ver, 4 ieee | Tree Growing: prim’s algorithm creates the tree by adding one edge at a time to the current ty, | process can start with a root vertex r (it can be any vertex). At any time, the subset ea s, A forms a single tree whereas Kruskal’s algorithm formed a forest. We add a single, “tt as a leaf to the tree. The process is illustrated in the following figure, Vertex Fig. 22.4, Analysis: It takes O(log V) to extract each vertex from the priority queue. For each incident ed, OAog v) time is spent in decreasing the key of the neighbouring vertex. Thus the total tie is O(log V + deg (u) log V). The other steps for updation tak. i BOton ¥ = de pi e constant time. So the total TW, A= > (log V + degree(u)logV) ueV = > (1+degree(u))log¥ ueV = log V_>\ (1+degree(u)) ueV We know that, Dd degree(u) = a7 eV TW, E) = (log V) (V + 28) OV + £) log V) Vis not ically greate ing ti ich i aa Kruskal’ glgoithes sreater than E, so the running time is @(E log V) which is sa 0 EXAMPLE 22.3. Using Prim’s aleom it given graph Ti"é Prim’s algorithm find the minimum spanning tree of the followité= Minimum Spanning Tree TD NANA Fig. 22.5. ve NY AN S= @ SS Q= {b,c,d,e,f,g} A= Thos edge = {a,b} “I ve aS be Step 2. ge, YY OTN stay :D}} / lightest edge = {b,d}, {a,c} NEA NS A 3 Solution: Step 1. 5 Ne cA NES sziehe, Q= {ce,f.g} 10 eo 6 A= { {a,b}, {b.d}} ae a lightest edge = {d,c} XL ne 43 Step 4, oe teenie f9) © a (a,b), {b,d}, {c,d} } Ne 10 lightest edge = {c,f} x SY. Peles6.4.) (e.g) {a,b}, {b,d}, {c,d}, {c.f} } lightest edge = {f.g} fe} oO A= { {a,b}, {0,4}, {c.d}, {c.f}, {f.9}} \, 3 Ne ° © lightest edge = {fe} WZ 2 2 Step 7. cdefg} RO WY o. Maa @ Aillon.e9.001060,00.40) \ ‘0 os NN x aS A oe cA SOLVED EXAMPLES EXAMPLE 22.4, Let (u, v) be a minimum weight edge in a graph G. Show that (u, ) belongs to some minimum spanning tree of G. Solution: Let us consider that A is a subset of some MST T with edge (u, v) € A. Light edges of some cut with u and v on separate sides. That's why (u, v) is minimum weight edge in directed graph for some cut. EXAMPLE 22.5. Define spanning tree. Write an algorithm for finding the spanning tree using Kruskal’s method and analyze it, (UPTU, MCA, 200102) Solution: Refer Section 21.2, 21.3, Solution: Refer Section 21.4.a = Minimum Spanning Tree « 449 EXAMPLE 22.7. Find out the minimum spanning tree of the following graph. (UPTU, MCA, 2003-04) Fig. 22.6, Solution: Step 1. ® © © © © (43. {8), (©). (0). FD Step 2, We choose (E, D) © © © ' ® @ {(A), (B}, {C). (0, } (FH Step 3. We choose (F, B) 1A). (8, FD. (C) (E. OFFinal MST Fig. 22.7.ae Minimum Spanning Treo 454 ‘otal minimum spanning Tree cost is 6 +4 434142 = 16. EXAMPLE 22.8. Indicate the order in which Kruskal’s algorithm would include edge Preonstructing a minimum spanning tree for the following graph. (UPTU, MCA, 2004-05) Fig. 22.8. © © Solution: Step 1. {(B), (CE), (F}, (G}, (HY) Step 2. We choose (E, G) (8), {(C), {E, G), {F}, (HY © © © Step 3. We choose (C, F*) ©——® {8}, (C.F), (E, Gh {HY} O+—® ® Step 4. Now we choose (F, H) ©——® {(B), (C. FH}. (E, GI) ©O+—-O)——-®. Design and Analysis of Algorithms Step 5. We choose (E, F) (8). {CE FG Hyp ‘Step 6. We choose (B, C) z—©) © (B,C, E76 Hy th are as ‘etwork given below as highway map and the number recorded next to ead the maximum elevation encountered in 1 to 12 on this highway. a node deen the are. A traveller plans to drive from dislikes high altit his traveller Path connecti, minimize the max altitude, ing node 1 to 12 that using a mini : the tudes and so would like to find mum spanning tree. er - Find the best path for the travel= Minimum Spanning Tree w Fig. 22.10. 4, Discuss Prim's algorithm to find MST with example and also find its analysis. 5. | What are spanning tree. Illustrate with examples. Also write down their various application. ¢. Find the minimum spanning tree for the following graph using prims algorithm and Kruskal’s algorithm. Fig. 22.11.
You might also like
19. W-11_L-1_Minimum Spanning Tree (MST), MST Kruskal’s Algorithm, MST Prim’s Algorithm.pptx
PDF
No ratings yet
19. W-11_L-1_Minimum Spanning Tree (MST), MST Kruskal’s Algorithm, MST Prim’s Algorithm.pptx
41 pages
Minimum Spanning Tree
PDF
No ratings yet
Minimum Spanning Tree
15 pages
Data Structures and Algorithms: Minimum Spanning Trees
PDF
No ratings yet
Data Structures and Algorithms: Minimum Spanning Trees
41 pages
Spanning Trees: Introduction To Algorithms
PDF
No ratings yet
Spanning Trees: Introduction To Algorithms
69 pages
Prim's and Kruskal's Algorithm
PDF
No ratings yet
Prim's and Kruskal's Algorithm
58 pages
Chapter11C
PDF
No ratings yet
Chapter11C
44 pages
dwvm unit3 (2)
PDF
No ratings yet
dwvm unit3 (2)
23 pages
18-Minimum Cost Spanning Tree_ Kruskal's Algorithm
PDF
No ratings yet
18-Minimum Cost Spanning Tree_ Kruskal's Algorithm
71 pages
Lecture 11 Minimum Spanning Tree
PDF
No ratings yet
Lecture 11 Minimum Spanning Tree
76 pages
08 Minumum Spanning Tree
PDF
No ratings yet
08 Minumum Spanning Tree
29 pages
Experiment No. 4 Design and Analysis Spanning Tree: Solve Minimum Cost Spanning Tree Problem Using Greedy Method
PDF
No ratings yet
Experiment No. 4 Design and Analysis Spanning Tree: Solve Minimum Cost Spanning Tree Problem Using Greedy Method
4 pages
Prims and Kruskal - ET - C2 - Roll No - 26
PDF
No ratings yet
Prims and Kruskal - ET - C2 - Roll No - 26
8 pages
CS124 Spring 2011
PDF
No ratings yet
CS124 Spring 2011
6 pages
04 CME4422 MinimumSpanningTree
PDF
No ratings yet
04 CME4422 MinimumSpanningTree
49 pages
CSE408 Minimum Spanning Tree (Prim's, Kruskal's)
PDF
No ratings yet
CSE408 Minimum Spanning Tree (Prim's, Kruskal's)
33 pages
Min Spanning Trees
PDF
No ratings yet
Min Spanning Trees
15 pages
Greedy Technique Definition:: On Each Step, The Choice Made Must Be
PDF
No ratings yet
Greedy Technique Definition:: On Each Step, The Choice Made Must Be
14 pages
MST - Lecture - 02
PDF
No ratings yet
MST - Lecture - 02
13 pages
5thAOAEXP
PDF
No ratings yet
5thAOAEXP
10 pages
3.5 Minimum cost spanning trees Kruskal and Prim’s algorithms
PDF
No ratings yet
3.5 Minimum cost spanning trees Kruskal and Prim’s algorithms
48 pages
Algorithm 8
PDF
No ratings yet
Algorithm 8
16 pages
Graphs MST
PDF
No ratings yet
Graphs MST
46 pages
Csn-261 (Data Structures Laboratory)
PDF
No ratings yet
Csn-261 (Data Structures Laboratory)
51 pages
Minimum Spanning Tree (Prim's and Kruskal's Algorithms)
PDF
No ratings yet
Minimum Spanning Tree (Prim's and Kruskal's Algorithms)
17 pages
Greedy MST
PDF
No ratings yet
Greedy MST
30 pages
Minimum Spanning Tree, Kruskal's and Prim's Algorithms, Applications in Networking
PDF
No ratings yet
Minimum Spanning Tree, Kruskal's and Prim's Algorithms, Applications in Networking
9 pages
Introduction To Algorithms: Concrete Example Concrete Example
PDF
No ratings yet
Introduction To Algorithms: Concrete Example Concrete Example
13 pages
Outline of Kruskal's Algorithm
PDF
No ratings yet
Outline of Kruskal's Algorithm
12 pages
Minimum Spanning Tree
PDF
No ratings yet
Minimum Spanning Tree
10 pages
Algo-Ch-3 Greedy Algorithms
PDF
No ratings yet
Algo-Ch-3 Greedy Algorithms
42 pages
11224A0A EX-5 (1)
PDF
No ratings yet
11224A0A EX-5 (1)
12 pages
DAA PPT -Minimum Spanning Tree
PDF
No ratings yet
DAA PPT -Minimum Spanning Tree
28 pages
MCA Spanning Tree CODE 212
PDF
100% (1)
MCA Spanning Tree CODE 212
8 pages
lec10mon
PDF
No ratings yet
lec10mon
53 pages
MODULE4-Greedy_methods[1]
PDF
No ratings yet
MODULE4-Greedy_methods[1]
17 pages
Minimum Spanning Tree001
PDF
No ratings yet
Minimum Spanning Tree001
19 pages
Prim and Krushkal Algorithm
PDF
No ratings yet
Prim and Krushkal Algorithm
4 pages
Minimum Cost Spanning Tree Unit-3
PDF
No ratings yet
Minimum Cost Spanning Tree Unit-3
20 pages
Ada Manual
PDF
No ratings yet
Ada Manual
31 pages
Assignment2 Last
PDF
No ratings yet
Assignment2 Last
49 pages
Lecture 12.1
PDF
No ratings yet
Lecture 12.1
45 pages
Final Dsa Report
PDF
No ratings yet
Final Dsa Report
14 pages
Minimum Spanning trees.pptx
PDF
No ratings yet
Minimum Spanning trees.pptx
20 pages
mcst
PDF
No ratings yet
mcst
12 pages
Minimum Spanning Trees - Cormen Book Ch 23
PDF
No ratings yet
Minimum Spanning Trees - Cormen Book Ch 23
17 pages
12 - Minimum Spanning Tree
PDF
No ratings yet
12 - Minimum Spanning Tree
5 pages
Prims and Kruskal
PDF
No ratings yet
Prims and Kruskal
8 pages
Showclassmst
PDF
No ratings yet
Showclassmst
17 pages
lecture13
PDF
No ratings yet
lecture13
47 pages
Algo 4
PDF
No ratings yet
Algo 4
23 pages
Minimum Spanning Trees (Ch. 23) ! Minimum Spanning Trees!
PDF
No ratings yet
Minimum Spanning Trees (Ch. 23) ! Minimum Spanning Trees!
5 pages
spanning Tree
PDF
No ratings yet
spanning Tree
35 pages
Graphs: Prim, Bellman-Ford, Floyd-Warshall. Solutions
PDF
No ratings yet
Graphs: Prim, Bellman-Ford, Floyd-Warshall. Solutions
4 pages
Prim Kruskal
PDF
No ratings yet
Prim Kruskal
36 pages
Kruskal's Algo Report
PDF
No ratings yet
Kruskal's Algo Report
17 pages
Kruskal's Algorithm Lab Report
PDF
No ratings yet
Kruskal's Algorithm Lab Report
11 pages
MST PDF
PDF
No ratings yet
MST PDF
3 pages
LatexAssignment
PDF
No ratings yet
LatexAssignment
4 pages
Kruskal Print
PDF
No ratings yet
Kruskal Print
18 pages
Dynamic Programming
PDF
No ratings yet
Dynamic Programming
43 pages
U3
PDF
No ratings yet
U3
35 pages
UNIT 4 (GRAPH) Data Structure
PDF
No ratings yet
UNIT 4 (GRAPH) Data Structure
58 pages
Discrete Structure Unit 2 Notes
PDF
No ratings yet
Discrete Structure Unit 2 Notes
33 pages
DSA Compressed
PDF
No ratings yet
DSA Compressed
65 pages
LAB1
PDF
No ratings yet
LAB1
5 pages