Download presentation

Presentation is loading. Please wait.

Published byBarrie Manning Modified about 1 year ago

1
Minimum Spanning Tree Graph Theory Basics - Anil Kishore

2
Definition A spanning graph is a sub-graph that contains all the vertices of the graph If a spanning sub-graph is connected and has no cycles, its a tree, a spanning tree 1 6 5 4 3 2 1 6 5 4 3 2

3
MST A graph can have many Spanning Trees Given a weighted ( edge weights ) graph, our goal is to find a spanning tree with minimum sum of edge weights in it, Minimum Spanning Tree (MST) A F E D C B 2 7 1 10 5 4 3 A F E D C B 2 7 1 5 4 3

4
Simple application Government is planning to connect cities by roads and has estimated the cost of construction of roads between some pairs of cities Find the minimum cost to construct roads such that any city is reachable from any other city

5
Prim’s Algorithm Algorithm Prim(G) Initialize an empty priority queue Q Initialize an empty set S to mark already finished vertices FOR-each u in V f[u] := +infinity Insert u into Q end-for WHILE Q is not empty u := delete minimum element from Q add u to S FOR-each edge e = ( u, v ) if ( v not in S ) and ( w(e) < f[v] ) decrease f[v] to w(e) end-if end-for end-while End-Prim

6
Running Prim’s Algorithm A F E D C B 2 7 1 10 5 4 3

7
Running Prim’s Algorithm A F E D C B 2 7 1 10 5 4 3 0

8
Running Prim’s Algorithm A F E D C B 2 7 1 10 5 4 3 0 7 2

9
Running Prim’s Algorithm A F E D C B 2 7 1 10 5 4 3 0 7 2

10
Running Prim’s Algorithm A F E D C B 2 7 1 10 5 4 3 0 7 2 3

11
Running Prim’s Algorithm A F E D C B 2 7 1 10 5 4 3 0 7 2 3

12
Running Prim’s Algorithm A F E D C B 2 7 1 10 5 4 3 0 1 2 3 4

13
Running Prim’s Algorithm A F E D C B 2 7 1 10 5 4 3 0 1 2 3 4

14
Running Prim’s Algorithm A F E D C B 2 7 1 10 5 4 3 0 1 2 3 4

15
Running Prim’s Algorithm A F E D C B 2 7 1 10 5 4 3 0 1 2 3 4

16
Running Prim’s Algorithm A F E D C B 2 7 1 10 5 4 3 0 1 2 3 4

17
Running Prim’s Algorithm A F E D C B 2 7 1 10 5 4 3 MST

18
Complexity of Prim’s Algorithm Using an array – O(m) decrease key operations, each O(1) – O(n) min-key operations, each O(n) – O( m + n 2 ) Using a binary heap ( priority queue – O(m) decrease key operations, each O(log n) – O(n) min-key operations, each O(log n) – O( m logn + n logn )

19
Kruskal’s Algorithm Algorithm Kruskal (G) Sort the edges of G in non-decreasing order of edge weights Initialize an empty tree T FOR-each edge e in sorted order if adding e to T does not for a cycle in T Add e to T end-if end-for End-Kruskal

20
Running Kruskal’s Algorithm A F E D C B 2 7 1 10 5 4 3

21
Running Kruskal’s Algorithm A F E D C B 2 7 1 10 5 4 3

22
Running Kruskal’s Algorithm A F E D C B 2 7 1 10 5 4 3

23
Running Kruskal’s Algorithm A F E D C B 2 7 1 10 5 4 3

24
Running Kruskal’s Algorithm A F E D C B 2 7 1 10 5 4 3

25
Running Kruskal’s Algorithm A F E D C B 2 7 1 10 5 4 3

26
Running Kruskal’s Algorithm A F E D C B 2 7 1 10 5 4 3

27
Running Kruskal’s Algorithm A F E D C B 2 7 1 10 5 4 3

28
Running Kruskal’s Algorithm A F E D C B 2 7 1 10 5 4 3

29
Running Kruskal’s Algorithm A F E D C B 2 7 1 10 5 4 3

30
Running Kruskal’s Algorithm A F E D C B 2 7 1 10 5 4 3 MST

31
Complexity of Kruskal’s Algorithm Using the union-find data structure – O(m logn) for sorting edges – Simple implementation of union-find : O(log n) to find representative of a set O(m logn) – Using Path compression of union-find : almost a constant per operation O( m )

32
References Introduction to Algorithms – Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein http://cgm.cs.mcgill.ca/~avis/courses/251/2012/slides/04mst.pdf http://ww3.algorithmdesign.net/handouts/MST.pdf - End -

Similar presentations

OK

Graph (II) Shortest path, Minimum spanning tree GGuy 19-3-2011.

Graph (II) Shortest path, Minimum spanning tree GGuy 19-3-2011.

© 2018 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google