Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Pertemuan 13 Minimum Spanning Tree (MST) Matakuliah: T0534/Struktur Data Tahun: 2005 Versi: September 2005.

Similar presentations


Presentation on theme: "1 Pertemuan 13 Minimum Spanning Tree (MST) Matakuliah: T0534/Struktur Data Tahun: 2005 Versi: September 2005."— Presentation transcript:

1 1 Pertemuan 13 Minimum Spanning Tree (MST) Matakuliah: T0534/Struktur Data Tahun: 2005 Versi: September 2005

2 2 Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : menerangkan algoritma untuk MST (TIK-11)..

3 3 Outline Materi Spanning Tree. Algoritma untuk MST : –Prim –Kruskal –Sollin

4 4 Spanning Trees Spanning (ST) Tree is any tree that consist solely of edges in Graph (G). DFS and BFS can be used to create ST : DFS : depth first spanning tree. BFS : breadth first spanning tree.

5 5 MST MST is spanning tree of least cost (weight). Three different algorithms (greedy method) can be used to obtain a minimum spanning tree of connected undirected graph. Prim Kruskal Sollin

6 6 T = 0 TV={1} {start with vertex 1 and no edges } done = false While T contains less than n-1 edges and not done Do Begin Let (u,v) be a least-cost edge such that u is element of TV and v is not element of TV If there is no such edge Then done = true ElseAdd v to TV and (u,v) to T End If T contains fewer than n-1 edges Then “No Spanning Tree” Prim’s Algorithm

7 7 uvTVTNotesFigure --{1}{}Initial 16{1,6}{(1,6)}add 6 to TV, add (1,6) to Tb 65{1,6,5}{(1,6),(6,5)}add 5 to TV, add (6,5) to Tc 54(1,6,5,4}{(1,6),(6,5),(5,4)}add 4 to TV, add (5,4) to Td 43(1,6,5,4,3}{(1,6),(6,5),(5,4),(4,3)}add 3 to TV, add (4,3) to Te 32(1,6,5,4,3,2}{(1,6),(6,5),(5,4),(4,3),(3,2)}add 2 to TV, add (3,2) to Tf 27(1,6,5,4,3,2,7}{(1,6),(6,5),(5,4),(4,3),(3,2),(2,7)}add 7 to TV, add (2,7) to Tg T e r m i n a t e n=7 Summary of Prim’s Algorithm

8 8 Example of Prim’s Algorithm 1 2 3 4 5 6 7 (a)(b)(c)(d) 1 2 3 4 5 6 7 10 2524 22 18 14 16 12 28 (e) 12 10 25 1 2 3 4 5 6 7 10 25 22 1 2 3 4 5 6 7 10 22 25 (g) 14 1 2 3 4 5 6 7 10 12 16 25 22 1 5 6 7 10 2 3 4 (f) 16 1 2 3 4 5 6 7 10 12 25 22

9 9 T = 0 While T contains less than n-1 edges and E not empty Do Begin Choose an edge(v,w) from E If (v,w) does not create a cycle in T Then Add (v,w) to T ElseDiscard(v,w) End If T contains fewer than n-1 edges Then “No Spanning Tree” Kruskal’s Algorithm

10 10 Summary of Kruskal’s Algorithm EdgeWeightTNotesFigure --{}Initialb (1,6)10{(1,6)}add (1,6) to Tc (3,4)12{(1,6),(3,4)}add (3,4) to Td (2,7)14{(1,6),(3,4),(2,7)}add (2,7) to Te (2,3)16{(1,6),(3,4),(2,7),(2,3)}add (2,3) to Tf (4,7)18{(1,6),(3,4),(2,7),(2,3)}discard (4,7) (4,5)22{(1,6),(3,4),(2,7),(2,3),(4,5)}add (4,5) to Tg (5,7)24{(1,6),(3,4),(2,7),(2,3),(4,5)}discard (5,7) (5,6)25{(1,6),(3,4),(2,7),(2,3),(4,5),(5,6)}add (5,6) to Th T e r m i n a t e

11 11 Example of Kruskal’s Algorithm 1 2 3 4 5 6 7 (b) 1 2 3 4 5 6 7 (c) 10 1 2 3 4 5 6 7 (d) 1012 (a) 1 2 3 4 5 6 7 10 2524 22 18 14 16 12 28 1 2 3 4 5 6 7 (e) 10 12 14 1 2 3 4 5 6 7 (f) 10 12 14 16 1 2 3 4 5 6 7 (g) 10 12 14 16 22 1 2 3 4 5 6 7 (h) 10 12 14 16 22 25

12 12 Sollin’s Algorithm Selects several edges at each stage. At the start of stage, the selected edges, together with all n graph vertices, from spanning forest. This edge is minimum-cost edge that has exactly one vertex is the tree. The selected edges are added to the spanning tree being constructed. It is possible for two trees in the forest to select the same edge. So, multiple copies of the same edges are to be eliminated. Also when a graph has several edges with the same cost, it is possible for two tress to select two different edges that connect them together. These edges will, of course, have the same cost; only one of these should be retained. At the start of the first stage, the set of selected edges is empty. The algorithm terminates when there is only one tree at the end of a stage or when no edges remain to be selected.

13 13 Summary of Sollin’s Algorithm NotesSelected EdgesFigure Initial{} Select edge for each of the vertices{(1,6),(2,7),(3,4),(4,3),(5,4),(6,1),(7,2)} Eliminate the duplicate edges{(1,6),(2,7),(3,4),(5,4)}b Select least cost for joining the forest into tree{(1,6),(2,7),(3,4),(5,4),(6,5),(2,3)}c T e r m i n a t e

14 14 1 2 3 4 5 6 7 (a) 10 2524 22 18 14 16 12 28 1 2 3 4 5 6 7 (b) 10 22 14 12 1 2 3 4 5 6 7 (c) 10 22 14 12 16 25 Example of Sollin’s Algorithm

15 15 Selesai


Download ppt "1 Pertemuan 13 Minimum Spanning Tree (MST) Matakuliah: T0534/Struktur Data Tahun: 2005 Versi: September 2005."

Similar presentations


Ads by Google