Minimum Spanning Trees

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Weighted graphs Example Consider the following graph, where nodes represent cities, and edges show if there is a direct flight between each pair of cities.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Minimum Spanning Trees Definition Two properties of MST’s Prim and Kruskal’s Algorithm –Proofs of correctness Boruvka’s algorithm Verifying an MST Randomized.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Minimum Spanning Tree Algorithms
Spanning Trees.
Spanning Trees. 2 Spanning trees Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges.
CS 206 Introduction to Computer Science II 11 / 10 / 2008 Instructor: Michael Eckmann.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 25: Graph Traversal, DAGs, and Weighted Graphs.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Graphs & Graph Algorithms 2 Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 10 Instructor: Paul Beame.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
Graphs & Graph Algorithms 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
Minimum Spanning Trees
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.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
COMP 261 Lecture 12 Disjoint Sets. Menu Kruskal's minimum spanning tree algorithm Disjoint-set data structure and Union-Find algorithm Administrivia –Marking.
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
COSC 2007 Data Structures II Chapter 14 Graphs III.
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.
Minimum-Cost Spanning Tree CS 110: Data Structures and Algorithms First Semester,
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
COMP261 Lecture 7 A* Search. A* search Can we do better than Dijkstra's algorithm? Yes! –want to explore more promising paths, not just shortest so far.
COMP261 Lecture 6 Dijkstra’s Algorithm. Connectedness Is this graph connected or not? A Z FF C M N B Y BB S P DDGG AA R F G J L EE CC Q O V D T H W E.
1 Minimum Spanning Trees (some material adapted from slides by Peter Lee, Ananda Guna, Bettina Speckmann)
Minimum Spanning Trees CS 146 Prof. Sin-Min Lee Regina Wang.
Minimum Spanning Trees CSE 373 Data Structures Lecture 21.
Lecture 19 Minimal Spanning Trees CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
Data Structures & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Graph Search Applications, Minimum Spanning Tree
COMP261 Lecture 6 Dijkstra’s Algorithm.
Minimum Spanning Tree Chapter 13.6.
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Minimum Spanning Trees and Shortest Paths
Short paths and spanning trees
Data Structures & Algorithms Graphs
Minimum-Cost Spanning Tree
Minimum Spanning Tree.
Minimum Spanning Tree.
Minimum Spanning Tree.
Graphs & Graph Algorithms 2
CSE 373 Data Structures and Algorithms
Spanning Trees.
Minimum-Cost Spanning Tree
Minimum-Cost Spanning Tree
Hannah Tang and Brian Tjaden Summer Quarter 2002
Minimum Spanning Tree Algorithms
Minimum Spanning Trees
Minimum Spanning Tree.
Minimum Spanning Trees
CSE 373: Data Structures and Algorithms
CSC 380: Design and Analysis of Algorithms
Minimum spanning trees
CSE 373: Data Structures and Algorithms
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
CSE 373: Data Structures and Algorithms
Minimum-Cost Spanning Tree
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Minimum Spanning Trees COMP 261 Lecture 11 Minimum Spanning Trees

Spanning tree A spanning tree of a connected, undirected graph, is a subgraph that contains all the nodes but is a tree (no cycles).

Minimum spanning tree Minimum spanning tree of a weighted connected, undirected graph is a spanning tree with total weight no greater than the total weight of any other spanning tree. Example use: Find cheapest way to connect a set of towns/substations/cell towers with power/communication lines. May not be the shortest paths: 1 5

Prims Algorithm Minimum Spanning Tree: Idea: Grow the spanning tree from a seed node, always choosing the lowest weight edge to an unconnected node. B 5 7 C 1 A D 3 9 4 2 10 I 1 4 6 17 H E 6 J 3 8 10 18 23 14 F G 25

Prim's algorithm Given: a graph with weighted edges. Initialise fringe to have a dummy edge to the start node Repeat until all nodes visited: Choose from fringe a minimum weight edge to an unvisited node Add the edge to the spanning tree Visit the node at the other end of the edge, Add the unvisited neighbours of the node to the fringe Questions: What data structures do you use to represent the graph? How do you find the smallest edge from fringe efficiently? How do you tell if an edge is out of or within visited ? How do you represent the output tree? graph must be connected and must have non-negative weights.

Refining Prim's alg, explicit graphs Given: a graph with N nodes and E weighted edges represented as an adjacency list, where nodes have a visited flag and each edge has a intree flag Initialise: for each node, node.visited and node.intree false, count  0 fringe  priority queue of <length, edge, node> Pick a node n, fringe.enque(  0, -, n  ) Repeat until count = N or fringe is empty: <length, edge , node>  fringe.dequeue If not node.visited then node.visited ← true, edge.intree ← true count ++ for each edge out of node to neighbour if not neighbour.visited then add <edge.length, edge, neighbour> to fringe priority small length ⇒ high priority

Analysing Prim’s algorithm Prim’s algorithm is a best first search (rather than depth first) What’s the cost of the algorithm? Assume: N nodes, E edges What kind of graph makes it fail?

Kruskal's algorithm Alternative algorithm for minimum spanning trees: Idea: Connect small trees together, always choosing the lowest weight edge. Given: a graph with weighted edges. Initialise forest to be a set of trees, each containing one node Repeat until forest contains only one tree: Choose a minimum weight edge that connects two trees in forest Add the edge to the spanning tree and combine the two trees graph must be connected and must have non-negative weights.

Graph Algorithms Minimum Spanning Tree: Kruskal's Algorithm Questions: How do you find the smallest edge efficiently? How do you efficiently determine if an edge connects two trees or not? B 5 7 C 1 A D 3 9 4 2 10 I 1 4 6 17 H E 6 J 3 8 10 18 23 14 F G 25

Refining Kruskal's algorithm Given: a graph with N nodes and E weighted edges forest ← a set of N sets of nodes, each containing one node of the graph edges ← a priority queue of all the edges: 〈n1, n2, length〉 spanningTree ← an empty set of edges Repeat until forest contains only one tree or edges is empty: 〈n1, n2, length〉 ← dequeue(edges) If n1 and n2 are in different sets in forest then merge the two sets in forest Add edge to the spanningTree return spanningTree Implementing forest : set of sets with two operations: findSet(n1) =?= findSet(n2) = "find" the set that n is in merge(s1, s2) = replace s1, s2 by their "union" priority: short edges first What's the cost? graph must be connected and must have non-negative weights.

Greedy algorithms Both Prim's and Kruskal's algorithms are "greedy": Every time they make a decision (to add an edge to the spanning tree), they commit to it. no backtracking no sidetracks that get abandoned. Greedy algorithms work when There is enough information at each point to make a correct decision optimal solutions to sub-problems are always sub-solutions of the full problem. Greedy algorithms are generally fast.