Minimum-Cost Spanning Tree CS 110: Data Structures and Algorithms First Semester, 2010-2011.

Slides:



Advertisements
Similar presentations
© 2004 Goodrich, Tamassia Minimum Spanning Trees1 JFK BOS MIA ORD LAX DFW SFO BWI PVD
Advertisements

Lecture 15. Graph Algorithms
© 2004 Goodrich, Tamassia Minimum Spanning Trees1 JFK BOS MIA ORD LAX DFW SFO BWI PVD
Spring 2007Shortest Paths1 Minimum Spanning Trees JFK BOS MIA ORD LAX DFW SFO BWI PVD
Shortest Paths and Dijkstra's Algorithm CS 110: Data Structures and Algorithms First Semester,
Shortest Paths1 C B A E D F
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Spanning Trees. 2 Spanning trees Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges.
Minimum Spanning Trees1 JFK BOS MIA ORD LAX DFW SFO BWI PVD
© 2004 Goodrich, Tamassia Shortest Paths1 Shortest Paths (§ 13.6) Given a weighted graph and two vertices u and v, we want to find a path of minimum total.
© 2004 Goodrich, Tamassia Minimum Spanning Trees1 Minimum Spanning Trees (§ 13.7) Spanning subgraph Subgraph of a graph G containing all the vertices of.
Minimum Spanning Trees1 JFK BOS MIA ORD LAX DFW SFO BWI PVD
CSC311: Data Structures 1 Chapter 13: Graphs II Objectives: Graph ADT: Operations Graph Implementation: Data structures Graph Traversals: DFS and BFS Directed.
Shortest Paths1 C B A E D F
© 2004 Goodrich, Tamassia Shortest Paths1 C B A E D F
Spanning Trees. Spanning trees Suppose you have a connected undirected graph –Connected: every node is reachable from every other node –Undirected: edges.
CSC 213 Lecture 24: Minimum Spanning Trees. Announcements Final exam is: Thurs. 5/11 from 8:30-10:30AM in Old Main 205.
1 Minimum Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting.
Minimum Spanning Trees. Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a.
1 Minimum Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting.
Weighted Graphs In a weighted graph, each edge has an associated numerical value, called the weight of the edge Edge weights may represent, distances,
WEIGHTED GRAPHS. Weighted Graphs zGraph G = (V,E) such that there are weights/costs associated with each edge Õw((a,b)): cost of edge (a,b) Õrepresentation:
© 2010 Goodrich, Tamassia Shortest Paths1 C B A E D F
1 Minimum Spanning Tree Problem Topic 10 ITS033 – Programming & Algorithms Asst. Prof. Dr. Bunyarit Uyyanonvara IT Program, Image and Vision Computing.
Shortest Paths C B A E D F
Graphs Part 2. Shortest Paths C B A E D F
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
Minimum spanning trees Aims: To know the terms: tree, spanning tree, minimum spanning tree. To understand that a minimum spanning tree connects a network.
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
Shortest Paths 1 Chapter 7 Shortest Paths C B A E D F
Lecture 16. Shortest Path Algorithms
Shortest Paths and Dijkstra’s Algorithm CS 105. SSSP Slide 2 Single-source shortest paths Given a weighted graph G and a source vertex v in G, determine.
1 Dijkstra’s Algorithm Dr. Ying Lu RAIK 283 Data Structures & Algorithms.
Chapter 8 Dynamic Programming Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Minimum Spanning Trees CS 146 Prof. Sin-Min Lee Regina Wang.
© 2010 Goodrich, Tamassia Minimum Spanning Trees1 JFK BOS MIA ORD LAX DFW SFO BWI PVD
CSC 213 – Large Scale Programming. Minimum Spanning Tree (MST)  Spanning subgraph  Subgraph w/ all vertices ORD PIT ATL STL DEN DFW DCA
1 Weighted Graphs CSC401 – Analysis of Algorithms Lecture Notes 16 Weighted Graphs Objectives: Introduce weighted graphs Present shortest path problems,
Data Structures and Algorithms1 Data Structures and algorithms (IS ZC361) Weighted Graphs – Shortest path algorithms – MST S.P.Vimal BITS-Pilani
Minimum- Spanning Trees
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
CHAPTER 13 GRAPH ALGORITHMS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
Lecture 19 Minimal Spanning Trees CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
© 2010 Goodrich, Tamassia Shortest Paths1 C B A E D F
© 2010 Goodrich, Tamassia Minimum Spanning Trees1 JFK BOS MIA ORD LAX DFW SFO BWI PVD
1 COMP9024: Data Structures and Algorithms Week Twelve: Graphs (II) Hui Wu Session 1, 2014
Minimum-cost spanning tree
Shortest Paths C B A E D F Shortest Paths
Minimum-Cost Spanning Tree and Kruskal’s Algorithm
COMP9024: Data Structures and Algorithms
Minimum Spanning Trees
Shortest Paths C B A E D F Shortest Paths
Shortest Paths C B A E D F Shortest Paths 1
Minimum Spanning Trees
Minimum Spanning Tree Chapter 13.6.
Shortest Paths C B A E D F Shortest Paths
Minimum Spanning Tree 11/3/ :04 AM Minimum Spanning Tree
Shortest Paths C B A E D F Shortest Paths
Shortest Paths C B A E D F
Minimum Spanning Tree.
Minimum Spanning Tree.
Shortest Paths C B A E D F Shortest Paths
Shortest Paths C B A E D F Shortest Paths
Minimum Spanning Trees
Chapter 13 Graph Algorithms
Minimum Spanning Trees
Single-source shortest paths
Shortest Paths.
Minimum Spanning Trees
Weighted Graphs C B A E D F Sequences
Presentation transcript:

Minimum-Cost Spanning Tree CS 110: Data Structures and Algorithms First Semester,

Minimum-Cost Spanning Tree ► Given a weighted graph G, determine a spanning tree with minimum total edge cost ► Recall: spanning subgraph means all vertices are included, tree means the graph is connected and has no cycles ► Useful in applications that ensure connectivity of nodes of optimal cost

Kruskal’s Algorithm ► Solves the minimum-cost spanning tree problem ► Strategy: repeatedly select the lowest- cost edge as long as it does not form a cycle with previously selected edges ► Stop when n-1 edges have been selected (n is the number of vertices)

Kruskal’s Algorithm ► Use a priority queue of edges to facilitate selection of lowest-edge cost (just disregard edges that form a cycle) ► Time complexity O( m log m )  O( m log n )

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

MIA JFK PVD BOS DFW SFO LAX BWI ORD Kruskal’s Algorithm

Pseudo-Code: Kruskal function Kruskal( Graph g ) n <-- number of vertices in g for each vertex v in g define an elementary cluster C(v) <-- {v} E <-- all edges in G Es <-- sort(E) T <-- null // will contain edges of MCST i <-- 0 while T has edges fewer than n-1 (u, v) <-- Es[i] Let C(v) be the cluster containing v Let C(u) be the cluster containing u if C(v) != C(u) then Add edge (v, u) to T Merge C(v) and C(u) into one cluster i = i + 1 return tree T

Prim’s Algorithm ► Start at a specific vertex ► Choose the edge of minimum cost which is incident on the vertex being considered ► Add the new vertex on which the previously chosen edge is incident ► Repeat until the MCST is found ► Unlike Kruskal’s, make sure that a tree is always build as the algorithm progresses

Prim’s Algorithm ► Start at a specific vertex ► Choose the edge of minimum cost which is incident on the vertex being considered ► Add the new vertex on which the previously chosen edge is incident ► Repeat until the MCST is found ► Unlike Kruskal’s, make sure that a tree is always build as the algorithm progresses

Prim’s Algorithm a b g c f e d h i

Prim’s Algorithm a b g c f e d h i

Prim’s Algorithm a b g c f e d h i

Prim’s Algorithm a b g c f e d h i

Prim’s Algorithm a b g c f e d h i

Prim’s Algorithm a b g c f e d h i

Prim’s Algorithm a b g c f e d h i

Prim’s Algorithm a b g c f e d h i

Prim’s Algorithm a b g c f e d h i

Prim’s Algorithm a b g c f e d h i

Prim’s Algorithm a b g c f e d h i

Pseudo-Code: Prim function Prim( Graph g ) select any vertex v of g D[v] <-- 0 for each vertex u != v D[u] <-- infinity Initialize T <-- null Initalize a priority queue Q with an item ( (u, null), D[u] ) for each vertex u, where (u, null) is the element and D[u] is the key while Q is not empty (u, e) <-- Q.removeMin() Add vertex u and edge e to T for each vertex z adjacent to u such that z is in Q if w( (u,z) ) < D[z] D[z] <-- w( (u,z) ) Change to (z, (u,z)) the element of vertex z in Q Change to D[z] the key of vertex z in Q return the tree T