KRUSKAL'S algorithm from chaitra
-
Upload
guest1f4fb3 -
Category
Education
-
view
7.641 -
download
9
Transcript of KRUSKAL'S algorithm from chaitra
![Page 1: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/1.jpg)
1
KUVEMPU UNIVERSITY KUVEMPU UNIVERSITY Department of Computer ScienceDepartment of Computer Science
Jnana SahyadriJnana SahyadriShankarghattaShankarghatta
Seminar onSeminar on
““Kruskal’s Algorithm ”Kruskal’s Algorithm ”
Presented by, Presented by, Chaitra.M.S Chaitra.M.S 33rdrd sem , M.Sc, sem , M.Sc, Dept. Of Computer Science,Dept. Of Computer Science, Shankarghatta.Shankarghatta.
Under the guidance of,Under the guidance of, Suresh.M,Suresh.M,
Dept. Of Computer Science,Dept. Of Computer Science, Shankarghatta.Shankarghatta.
![Page 2: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/2.jpg)
2
Contents
• Spanning trees• Finding a spanning tree• Minimum-cost spanning trees• Kruskal’s algorithm And example
![Page 3: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/3.jpg)
Spanning Trees
![Page 4: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/4.jpg)
4
Spanning trees
• Suppose you have a connected undirected graph– Connected: every node is reachable from every other node
– Undirected: edges do not have an associated direction
• ...then a spanning tree of the graph is a connected subgraph in which there are no cycles
A connected,undirected graph
Four of the spanning trees of the graph
![Page 5: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/5.jpg)
5
Finding a spanning tree
• To find a spanning tree of a graph, pick an initial node and call it part of the spanning tree do a search from the initial node:
each time you find a node that is not in the spanning tree, add to the spanning tree both the new node and the edge you followed to get to it
An undirected graph
![Page 6: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/6.jpg)
6
Minimizing costs
• Suppose you want to supply a set of houses (say, in a new subdivision) with:– electric power
– water
– sewage lines
– telephone lines
• To keep costs down, you could connect these houses with a spanning tree (of, for example, power lines)– However, the houses are not all equal distances apart
• To reduce costs even further, you could connect the houses with a minimum-cost spanning tree
![Page 7: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/7.jpg)
7
Minimum-cost spanning trees
• Suppose you have a connected undirected graph with a weight (or cost) associated with each edge
• The cost of a spanning tree would be the sum of the costs of its edges
• A minimum-cost spanning tree is a spanning tree that has the lowest cost
A B
E D
F C
16
19
21 11
33 14
1810
6
5
A connected, undirected graph
A B
E D
F C
1611
18
6
5
A minimum-cost spanning tree
A B
E D
F C
16
19
21 11
33 14
1810
6
5
A connected, undirected graph
![Page 8: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/8.jpg)
8
Kruskal algorithm(E,cost,n,t)//E is set of edges in G .G has n vertices.Cost[u,v] is //cost of edge(u,v).t is the set of edges in minimum-cost //spanning tree.the final cost is returned.
{ //construct a heap out of the edge costs using heapify For i=:1 to n do parent[i]:=-1;//each vertex is in a different set.i:=0;mincost:=0.0;
While((i<n-1) and (heap not empty)) do{ //delete a minimum cost edje(u,v) from the heap and reheapify using
Adjust; j:=Find(u); k:=Find(v);
![Page 9: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/9.jpg)
9
If (j!=k) then { i:=i+1; t[i,1]:=u; t[i,2]:=v; mincost:=mincost+cost[u,v]; union(j,k); } } if(i!=n-1) then write(“no spanning tree”); else return mincost;
}
![Page 10: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/10.jpg)
10
Example graph
![Page 11: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/11.jpg)
11
![Page 12: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/12.jpg)
12
![Page 13: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/13.jpg)
13
![Page 14: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/14.jpg)
14
![Page 15: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/15.jpg)
15
![Page 16: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/16.jpg)
16
![Page 17: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/17.jpg)
17
![Page 18: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/18.jpg)
18
![Page 19: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/19.jpg)
19
Minimum cost spanning tree we obtained finally
![Page 20: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/20.jpg)
20
Any queries???????????
![Page 21: KRUSKAL'S algorithm from chaitra](https://reader033.fdocuments.in/reader033/viewer/2022061506/55619facd8b42ad9538b4948/html5/thumbnails/21.jpg)
21
Thank U………………