Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

Size: px
Start display at page:

Download "Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree"

Transcription

1 Algorithms and Theory of Computation Lecture 5: Minimum Spanning Tree Xiaohui Bei MAS 714 August 31, 2017 Nanyang Technological University MAS 714 August 31, / 30

2 Minimum Spanning Trees (MST) A weighted graph is a graph in which each edge e is associated with a numerical weight c e. Spanning Tree A spanning tree of an undirected connected graph G = (V, E) is a set of edges T E such that T forms a tree, and (V, T) is connected. In a weighted graph G, a minimum spanning tree is a spanning tree with the smallest sum of edge weights MST Find a minimum spanning tree of a weighted graph G. Nanyang Technological University MAS 714 August 31, / 30

3 Example a 7 5 b 8 c 7 d 9 15 e 5 6 f g Nanyang Technological University MAS 714 August 31, / 30

4 Applications A basic and fundamental problem in graph theory, often used to measure costs to establish connections between vertices. 1 Network Design: designing networks with minimum cost while guaranting connectivity 2 Approximation Algorithm: can be used to approximate other hard problems such as Traveling Salesman Problem, Steiner Trees, etc. Nanyang Technological University MAS 714 August 31, / 30

5 Greedy Template Algorithm: SomeGreedyMSTAlgorithm(G): Initialize T = ; // T will store edges of a MST while T is not a spanning tree of G do choose e E that satisfies condition; add e to T; return T Which edges, and in what order, should be processed and added to the spanning tree? Nanyang Technological University MAS 714 August 31, / 30

6 Kruskal s Algorithm Process edges in the order of their costs (in increasing order), and add edges to T as long as they don t form a cycle. a 7 5 b 8 c 7 d 9 15 e 5 6 f g Nanyang Technological University MAS 714 August 31, / 30

7 Prim s Algorithm T maintained by the algorithm will be a tree, starting from a single vertex. In each iteration, pick edges with least attachedment cost to T. a 7 5 b 8 c 7 d 9 15 e 5 6 f g Nanyang Technological University MAS 714 August 31, / 30

8 Correctness of MST algorithms Many different MST algorithms. All of them rely on some basic properties of MSTs. Assumption For simplicity, we assume that edge costs are distinct, that is no two edge costs are equal. Nanyang Technological University MAS 714 August 31, / 30

9 Cut Cut Given a graph G = (V, E), a cut is a partition of the vertices into two disjoint subsets. Edges that have one endpoint in each subset of the partition are the edges of the cut, and these edges are said to cross the cut. S V \ S Nanyang Technological University MAS 714 August 31, / 30

10 Safe Edges Safe Edges An edge e is a safe edge if there exists a partition of V into S and V\S, and e is the unique minimum cost edge crossing this partition. S V \ S Safe edge in the cut (S, V \ S) Nanyang Technological University MAS 714 August 31, / 30

11 Cut Property Theorem Given an undirected connected graph G with distinct edge costs, the set of safe edges in G form the unique MST of G. Proof. Prove the lemma in two steps: 1 If e is a safe edge, then every MST contains e. 2 The set of safe edges form a connected graph that covers every vertex. Nanyang Technological University MAS 714 August 31, / 30

12 Cut Property Lemma 1 If e is a safe edge, then every MST contains e. Proof. Assume by contradiction that e is not in some MST T. 1 e = {u, v} is safe = there is an S V such that e is the unique minimum cost edge crossing S. 2 Adding e to T creates a cycle C in T {e}. 3 There must exist another edge e in T cross this cut. 4 T = (T\{e }) {e} is a spanning tree of lower cost. Nanyang Technological University MAS 714 August 31, / 30

13 Cut Property Lemma 2 The set of safe edges from a connected graph that covers every vertex. Proof. 1 Assume not. Let S be a connected component in the graph induced by safe edges. 2 Let e be the smallest cost edge crossing S = e is a safe edge. Nanyang Technological University MAS 714 August 31, / 30

14 Kruskal s Algorithm Process edges in the order of their costs (in increasing order), and add edges to T as long as they don t form a cycle. Algorithm: Kruskal(G): Initialize T = ; // T will store edges of a MST while T is not a spanning tree of G do choose e E of minimum cost; if T {e} does not contain cycles then add e to T; return T Presort edges by costs. Choosing minimum then takes O(1) time. Do DFS on T {e}. Takes O(n) time. Total time O(m log m) + O(mn) = O(mn). Nanyang Technological University MAS 714 August 31, / 30

15 Correctness Process edges in the order of their costs (in increasing order), and add edges to T as long as they don t form a cycle. Only need to show that all edges added are safe. Proof of Correctness. When e = (u, v) is added to the tree, let S and S be the connected components containing u and v respectively. e has minimum cost under all edges forming no cycle, hence e has minimum cost among all edges crossing the cut S (and also S ) e is a safe edge. Nanyang Technological University MAS 714 August 31, / 30

16 More Efficient Implementation Algorithm: SmarterKruskal(G): Initialize T = ; // T will store edges of a MST Put each vertex u V into a set by itself; foreach e = {u, v} E in the order of increasing costs do if u and v belong to different sets then add e to T; merge the two sets containing u and v; return T Need a data structure to: check if two elements belong to same set merge two sets Nanyang Technological University MAS 714 August 31, / 30

17 Data Structure: Union-Find Union-Find Store a set of disjoint sets with the following operations: 1 Make-Set(V): generate a set {v} for each vertex v V. Name of set {v} is v. 2 Find(u): find the name of the set containing vertex u. 3 Union(u, v): merge the sets named u and v. Name of the new set is either u or v. The running time of Kruskal algorithm will depend on the implementation of the data structure. Nanyang Technological University MAS 714 August 31, / 30

18 Union-Find: Implementation Sets are represented as trees, by pointers towards the roots. All elements in one tree belong to a set with root s name. Find(u): Traverse from u to the root Union(u, v): Make root of u (smaller set) point to root of v. Takes O(1) time. Each vertex u has a pointer parent(u) to its ancestor. s v w s v w u u Figure Figure: Union(Find(v), Find(u)) Nanyang Technological University MAS 714 August 31, / 30

19 New Implementation Algorithm: Make-Set(G): foreach u V do parent(u) = u; Algorithm: Find(u): while parent(u) u do u = parent(u); return u Algorithm: Union(u, v): ( parent(u) = u & parent(v) = v ) if component(u) component(v) then parent(u) = v else parent(v) = u set new componen size to component(u) + component(v). Nanyang Technological University MAS 714 August 31, / 30

20 Analysis Make-Set: O(n) time. Union: O(1) time. Find: O(depth of the tree) time. Proposition The maximum depth of trees in union-find is O(log n). Proof. Depth of tree(u) increases by at most 1 only when the set containing u changes its name. If depth of tree u increases then the size of the set containing u (at least) doubles. Maximum set size is n; so the depth of any tree is at most O(log n). Nanyang Technological University MAS 714 August 31, / 30

21 Speed up! When calling Find(u), we traverse the path from u to the root. Consecutive calls of find(u) traverse the same path. Idea: Path Compression Make all vertices on the path in Find(u) point to root directly. Nanyang Technological University MAS 714 August 31, / 30

22 Path Compression: Example Algorithm: Find(u): if parent(u) u then parent(u) = Find(parent(u)); return parent(u) r r v v w w u u Figure Figure: After Find(u) Nanyang Technological University MAS 714 August 31, / 30

23 Path Compression Question Does Path Compression help? Yes! Theorem With Path Compression, the amortized running time of Find operations is O(α(n)), where α(n) is the inverse of the Ackermann function A(n, n). Nanyang Technological University MAS 714 August 31, / 30

24 Ackermann and Inverse Ackermann Functions Ackermann function A(m, n) defined for m, n 0: n + 1 if m = 0 A(m, n) = A(m 1, 1) if m > 0 and n = 0 A(m 1, A(m, n 1)) if m > 0 and n > 0 A(3, n) = 2 n+3 3 A(4, 3) = α(n) is the inverse of A(n, n) For all practical purposes, α(n) 5. Nanyang Technological University MAS 714 August 31, / 30

25 Running time of Kruskal s Algorithm Using Union-Find data structure, Kruskal s Algorithm takes O(m) Find operations (two for each edge) O(n) Union operations (one for each edge added to T) 1 sorting operation Total time = O(mα(n) + n + m log m) = O(m log m) Nanyang Technological University MAS 714 August 31, / 30

26 Prim s Algorithm T maintained by the algorithm will be a tree, starting from a single vertex. In each iteration, pick edges with least attachedment cost to T. Algorithm: Prim(u): Initialize T = ; // T will store edges of a MST Initialize S = {1}; while T is not a spanning tree of G do choose e = (u, v) E of minimum cost such that u S and v V S; T = T {e}; S = S {v}; return T O(n) iterations O(m) time to pick edge e in each iteration Total running time = O(mn) Nanyang Technological University MAS 714 August 31, / 30

27 Correctness T maintained by the algorithm will be a tree, starting from a single vertex. In each iteration, pick edges with least attachedment cost to T. Proof of correctness. 1 If e is added to the tree, then e is safe Let S be the vertices connected by edges in T when e is added. e is the minimum cost edge crossing cut (S, V\S). 2 S is connected in each iteration and eventually S = V. Nanyang Technological University MAS 714 August 31, / 30

28 More Efficient Implementation Algorithm: SmarterPrim(u): Initialize T = ; // T will store edges of a MST Initialize S = {1}; for u / S, a(u) = arg min e=(u,v),v S c e ; while T is not a spanning tree of G do pick minimum a(u) = (u, v) ; T = T {a(u)}; S = S {u}; update array a; return T Maintain vertices in V\S in a priority queue. Nanyang Technological University MAS 714 August 31, / 30

29 Priority Queue Priority Queues Store a set S of n elements, where each element v S has an associated real/integer key k(v), with the following operations: 1 Make-Queue: create an empty queue 2 Find-Min: find the minimum key in S 3 Extract-Min: remove v S with the smallest key and return it 4 Decrease-Key(v, k (v)): decrease key of v from k(v) to k (v) 5 Add(v, k(v)): add new element v with key k(v) to S Very useful data structure, will discuss in detail in later lectures. Prim requires O(n) Extract-Min and O(m) Decrease-Key operations. Using standard Heaps, total time = O((m + n) log n). Using Fibonacci Heaps, total time = O(n log n + m). Nanyang Technological University MAS 714 August 31, / 30

30 More about MST There is an algorithm that runs in O(n + mα(n)) time. There is a randomized algorithm that runs in O(m + n) expected time. There is an algorithm using bit operations in RAM model that runs in O(m + n) time. Still open: Is there an O(n + m) time deterministic algorithm in the comparison model? Nanyang Technological University MAS 714 August 31, / 30

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree Algorithms and Theory of Computation Lecture 5: Minimum Spanning Tree Xiaohui Bei MAS 714 August 31, 2017 Nanyang Technological University MAS 714 August 31, 2017 1 / 30 Minimum Spanning Trees (MST) A

More information

Algorithms for Minimum Spanning Trees

Algorithms for Minimum Spanning Trees Algorithms & Models of Computation CS/ECE, Fall Algorithms for Minimum Spanning Trees Lecture Thursday, November, Part I Algorithms for Minimum Spanning Tree Sariel Har-Peled (UIUC) CS Fall / 6 Sariel

More information

2 A Template for Minimum Spanning Tree Algorithms

2 A Template for Minimum Spanning Tree Algorithms CS, Lecture 5 Minimum Spanning Trees Scribe: Logan Short (05), William Chen (0), Mary Wootters (0) Date: May, 0 Introduction Today we will continue our discussion of greedy algorithms, specifically in

More information

Algorithms and Theory of Computation. Lecture 7: Priority Queue

Algorithms and Theory of Computation. Lecture 7: Priority Queue Algorithms and Theory of Computation Lecture 7: Priority Queue Xiaohui Bei MAS 714 September 5, 2017 Nanyang Technological University MAS 714 September 5, 2017 1 / 15 Priority Queues Priority Queues Store

More information

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem Minimum Spanning Trees (Forests) Given an undirected graph G=(V,E) with each edge e having a weight w(e) : Find a subgraph T of G of minimum total weight s.t. every pair of vertices connected in G are

More information

CS 310 Advanced Data Structures and Algorithms

CS 310 Advanced Data Structures and Algorithms CS 0 Advanced Data Structures and Algorithms Weighted Graphs July 0, 07 Tong Wang UMass Boston CS 0 July 0, 07 / Weighted Graphs Each edge has a weight (cost) Edge-weighted graphs Mostly we consider only

More information

COP 4531 Complexity & Analysis of Data Structures & Algorithms

COP 4531 Complexity & Analysis of Data Structures & Algorithms COP 4531 Complexity & Analysis of Data Structures & Algorithms Lecture 9 Minimum Spanning Trees Thanks to the text authors who contributed to these slides Why Minimum Spanning Trees (MST)? Example 1 A

More information

Chapter 23. Minimum Spanning Trees

Chapter 23. Minimum Spanning Trees Chapter 23. Minimum Spanning Trees We are given a connected, weighted, undirected graph G = (V,E;w), where each edge (u,v) E has a non-negative weight (often called length) w(u,v). The Minimum Spanning

More information

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck Theory of Computing Lecture 10 MAS 714 Hartmut Klauck Seven Bridges of Königsberg Can one take a walk that crosses each bridge exactly once? Seven Bridges of Königsberg Model as a graph Is there a path

More information

Minimum spanning trees

Minimum spanning trees Minimum spanning trees [We re following the book very closely.] One of the most famous greedy algorithms (actually rather family of greedy algorithms). Given undirected graph G = (V, E), connected Weight

More information

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 4.5 Minimum Spanning Tree Minimum Spanning Tree Minimum spanning tree. Given a connected

More information

Dijkstra s algorithm for shortest paths when no edges have negative weight.

Dijkstra s algorithm for shortest paths when no edges have negative weight. Lecture 14 Graph Algorithms II 14.1 Overview In this lecture we begin with one more algorithm for the shortest path problem, Dijkstra s algorithm. We then will see how the basic approach of this algorithm

More information

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Computer Science & Engineering 423/823 Design and Analysis of Algorithms Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 05 Minimum-Weight Spanning Trees (Chapter 23) Stephen Scott (Adapted from Vinodchandran N. Variyam) sscott@cse.unl.edu Introduction

More information

CSE331 Introduction to Algorithms Lecture 15 Minimum Spanning Trees

CSE331 Introduction to Algorithms Lecture 15 Minimum Spanning Trees CSE1 Introduction to Algorithms Lecture 1 Minimum Spanning Trees Antoine Vigneron antoine@unist.ac.kr Ulsan National Institute of Science and Technology July 11, 201 Antoine Vigneron (UNIST) CSE1 Lecture

More information

Greedy Algorithms Part Three

Greedy Algorithms Part Three Greedy Algorithms Part Three Announcements Problem Set Four due right now. Due on Wednesday with a late day. Problem Set Five out, due Monday, August 5. Explore greedy algorithms, exchange arguments, greedy

More information

Greedy Algorithms. At each step in the algorithm, one of several choices can be made.

Greedy Algorithms. At each step in the algorithm, one of several choices can be made. Greedy Algorithms At each step in the algorithm, one of several choices can be made. Greedy Strategy: make the choice that is the best at the moment. After making a choice, we are left with one subproblem

More information

CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li

CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast

More information

Minimum Spanning Trees

Minimum Spanning Trees CSMPS 2200 Fall Minimum Spanning Trees Carola Wenk Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk 11/6/ CMPS 2200 Intro. to Algorithms 1 Minimum spanning trees Input: A

More information

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, ) Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 1. if >. 2. error new key is greater than current key 3.. 4.. 5. if NIL and.

More information

22 Elementary Graph Algorithms. There are two standard ways to represent a

22 Elementary Graph Algorithms. There are two standard ways to represent a VI Graph Algorithms Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths All-Pairs Shortest Paths 22 Elementary Graph Algorithms There are two standard ways to represent a graph

More information

We ve done. Introduction to the greedy method Activity selection problem How to prove that a greedy algorithm works Fractional Knapsack Huffman coding

We ve done. Introduction to the greedy method Activity selection problem How to prove that a greedy algorithm works Fractional Knapsack Huffman coding We ve done Introduction to the greedy method Activity selection problem How to prove that a greedy algorithm works Fractional Knapsack Huffman coding Matroid Theory Now Matroids and weighted matroids Generic

More information

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck Theory of Computing Lecture 10 MAS 714 Hartmut Klauck Data structures: Union-Find We need to store a set of disjoint sets with the following operations: Make-Set(v): generate a set {v}. Name of the set

More information

managing an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm

managing an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm Spanning Trees 1 Spanning Trees the minimum spanning tree problem three greedy algorithms analysis of the algorithms 2 The Union-Find Data Structure managing an evolving set of connected components implementing

More information

Minimum Spanning Trees. Lecture II: Minimium Spanning Tree Algorithms. An Idea. Some Terminology. Dr Kieran T. Herley

Minimum Spanning Trees. Lecture II: Minimium Spanning Tree Algorithms. An Idea. Some Terminology. Dr Kieran T. Herley Lecture II: Minimium Spanning Tree Algorithms Dr Kieran T. Herley Department of Computer Science University College Cork April 016 Spanning Tree tree formed from graph edges that touches every node (e.g.

More information

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 4.5 Minimum Spanning Tree Minimum Spanning Tree Minimum spanning tree. Given a connected

More information

CIS 121 Data Structures and Algorithms Minimum Spanning Trees

CIS 121 Data Structures and Algorithms Minimum Spanning Trees CIS 121 Data Structures and Algorithms Minimum Spanning Trees March 19, 2019 Introduction and Background Consider a very natural problem: we are given a set of locations V = {v 1, v 2,..., v n }. We want

More information

Algorithms and Data Structures: Minimum Spanning Trees (Kruskal) ADS: lecture 16 slide 1

Algorithms and Data Structures: Minimum Spanning Trees (Kruskal) ADS: lecture 16 slide 1 Algorithms and Data Structures: Minimum Spanning Trees (Kruskal) ADS: lecture 16 slide 1 Minimum Spanning Tree Problem Given: Undirected connected weighted graph (G, W ) Output: An MST of G We have already

More information

CSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

CSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo CSE 431/531: Analysis of Algorithms Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast algorithms to solve

More information

Minimum Spanning Trees

Minimum Spanning Trees Minimum Spanning Trees 1 Minimum- Spanning Trees 1. Concrete example: computer connection. Definition of a Minimum- Spanning Tree Concrete example Imagine: You wish to connect all the computers in an office

More information

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 8 Lecturer: David Wagner February 20, Notes 8 for CS 170

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 8 Lecturer: David Wagner February 20, Notes 8 for CS 170 UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 8 Lecturer: David Wagner February 20, 2003 Notes 8 for CS 170 1 Minimum Spanning Trees A tree is an undirected graph that is connected

More information

22 Elementary Graph Algorithms. There are two standard ways to represent a

22 Elementary Graph Algorithms. There are two standard ways to represent a VI Graph Algorithms Elementary Graph Algorithms Minimum Spanning Trees Single-Source Shortest Paths All-Pairs Shortest Paths 22 Elementary Graph Algorithms There are two standard ways to represent a graph

More information

What is a minimal spanning tree (MST) and how to find one

What is a minimal spanning tree (MST) and how to find one What is a minimal spanning tree (MST) and how to find one A tree contains a root, the top node. Each node has: One parent Any number of children A spanning tree of a graph is a subgraph that contains all

More information

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs Representations of Weighted Graphs (as Matrices) A B Algorithms and Data Structures: Minimum Spanning Trees 9.0 F 1.0 6.0 5.0 6.0 G 5.0 I H 3.0 1.0 C 5.0 E 1.0 D 28th Oct, 1st & 4th Nov, 2011 ADS: lects

More information

2pt 0em. Computer Science & Engineering 423/823 Design and Analysis of Algorithms. Lecture 04 Minimum-Weight Spanning Trees (Chapter 23)

2pt 0em. Computer Science & Engineering 423/823 Design and Analysis of Algorithms. Lecture 04 Minimum-Weight Spanning Trees (Chapter 23) 2pt 0em Computer Science & Engineering 423/823 Design and of s Lecture 04 Minimum-Weight Spanning Trees (Chapter 23) Stephen Scott (Adapted from Vinodchandran N. Variyam) 1 / 18 Given a connected, undirected

More information

Kruskal s MST Algorithm

Kruskal s MST Algorithm Kruskal s MST Algorithm CLRS Chapter 23, DPV Chapter 5 Version of November 5, 2014 Main Topics of This Lecture Kruskal s algorithm Another, but different, greedy MST algorithm Introduction to UNION-FIND

More information

Building a network. Properties of the optimal solutions. Trees. A greedy approach. Lemma (1) Lemma (2) Lemma (3) Lemma (4)

Building a network. Properties of the optimal solutions. Trees. A greedy approach. Lemma (1) Lemma (2) Lemma (3) Lemma (4) Chapter 5. Greedy algorithms Minimum spanning trees Building a network Properties of the optimal solutions Suppose you are asked to network a collection of computers by linking selected pairs of them.

More information

Chapter 5. Greedy algorithms

Chapter 5. Greedy algorithms Chapter 5. Greedy algorithms Minimum spanning trees Building a network Suppose you are asked to network a collection of computers by linking selected pairs of them. This translates into a graph problem

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 9: Minimum Spanning Trees Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Goal: MST cut and cycle properties Prim, Kruskal greedy algorithms

More information

Minimum Spanning Trees

Minimum Spanning Trees Minimum Spanning Trees Overview Problem A town has a set of houses and a set of roads. A road connects and only houses. A road connecting houses u and v has a repair cost w(u, v). Goal: Repair enough (and

More information

Minimum Spanning Trees

Minimum Spanning Trees Chapter 23 Minimum Spanning Trees Let G(V, E, ω) be a weighted connected graph. Find out another weighted connected graph T(V, E, ω), E E, such that T has the minimum weight among all such T s. An important

More information

Minimum Spanning Trees. COMPSCI 355 Fall 2016

Minimum Spanning Trees. COMPSCI 355 Fall 2016 Minimum Spanning Trees COMPSCI all 06 Spanning Tree Spanning Tree Spanning Tree Algorithm A Add any edge that can be added without creating a cycle. Repeat until the edges form a spanning tree. Algorithm

More information

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs Graphs and Network Flows ISE 411 Lecture 7 Dr. Ted Ralphs ISE 411 Lecture 7 1 References for Today s Lecture Required reading Chapter 20 References AMO Chapter 13 CLRS Chapter 23 ISE 411 Lecture 7 2 Minimum

More information

Advanced algorithms. topological ordering, minimum spanning tree, Union-Find problem. Jiří Vyskočil, Radek Mařík 2012

Advanced algorithms. topological ordering, minimum spanning tree, Union-Find problem. Jiří Vyskočil, Radek Mařík 2012 topological ordering, minimum spanning tree, Union-Find problem Jiří Vyskočil, Radek Mařík 2012 Subgraph subgraph A graph H is a subgraph of a graph G, if the following two inclusions are satisfied: 2

More information

23.2 Minimum Spanning Trees

23.2 Minimum Spanning Trees 23.2 Minimum Spanning Trees Kruskal s algorithm: Kruskal s algorithm solves the Minimum Spanning Tree problem in O( E log V ) time. It employs the disjoint-set data structure that is similarly used for

More information

Minimum Spanning Trees

Minimum Spanning Trees Minimum Spanning Trees Minimum Spanning Trees Representation of Weighted Graphs Properties of Minimum Spanning Trees Prim's Algorithm Kruskal's Algorithm Philip Bille Minimum Spanning Trees Minimum Spanning

More information

Minimum Spanning Trees. Minimum Spanning Trees. Minimum Spanning Trees. Minimum Spanning Trees

Minimum Spanning Trees. Minimum Spanning Trees. Minimum Spanning Trees. Minimum Spanning Trees Properties of Properties of Philip Bille 0 0 Graph G Not connected 0 0 Connected and cyclic Connected and acyclic = spanning tree Total weight = + + + + + + = Applications Network design. Computer, road,

More information

Minimum Spanning Trees My T. UF

Minimum Spanning Trees My T. UF Introduction to Algorithms Minimum Spanning Trees @ UF Problem Find a low cost network connecting a set of locations Any pair of locations are connected There is no cycle Some applications: Communication

More information

CS 561, Lecture 9. Jared Saia University of New Mexico

CS 561, Lecture 9. Jared Saia University of New Mexico CS 561, Lecture 9 Jared Saia University of New Mexico Today s Outline Minimum Spanning Trees Safe Edge Theorem Kruskal and Prim s algorithms Graph Representation 1 Graph Definition A graph is a pair of

More information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms, Lecture 1 /1/200 Introduction to Algorithms.04J/1.401J LECTURE 11 Graphs, MST, Greedy, Prim Graph representation Minimum spanning trees Greedy algorithms hallmarks. Greedy choice

More information

CS 6783 (Applied Algorithms) Lecture 5

CS 6783 (Applied Algorithms) Lecture 5 CS 6783 (Applied Algorithms) Lecture 5 Antonina Kolokolova January 19, 2012 1 Minimum Spanning Trees An undirected graph G is a pair (V, E); V is a set (of vertices or nodes); E is a set of (undirected)

More information

Algorithms (IX) Yijia Chen Shanghai Jiaotong University

Algorithms (IX) Yijia Chen Shanghai Jiaotong University Algorithms (IX) Yijia Chen Shanghai Jiaotong University Review of the Previous Lecture Shortest paths in the presence of negative edges Negative edges Dijkstra s algorithm works in part because the shortest

More information

Example of why greedy step is correct

Example of why greedy step is correct Lecture 15, Nov 18 2014 Example of why greedy step is correct 175 Prim s Algorithm Main idea:» Pick a node v, set A={v}.» Repeat: find min-weight edge e, outgoing from A, add e to A (implicitly add the

More information

6.1 Minimum Spanning Trees

6.1 Minimum Spanning Trees CS124 Lecture 6 Fall 2018 6.1 Minimum Spanning Trees A tree is an undirected graph which is connected and acyclic. It is easy to show that if graph G(V,E) that satisfies any two of the following properties

More information

Announcements Problem Set 5 is out (today)!

Announcements Problem Set 5 is out (today)! CSC263 Week 10 Announcements Problem Set is out (today)! Due Tuesday (Dec 1) Minimum Spanning Trees The Graph of interest today A connected undirected weighted graph G = (V, E) with weights w(e) for each

More information

COMP 355 Advanced Algorithms

COMP 355 Advanced Algorithms COMP 355 Advanced Algorithms Algorithms for MSTs Sections 4.5 (KT) 1 Minimum Spanning Tree Minimum spanning tree. Given a connected graph G = (V, E) with realvalued edge weights c e, an MST is a subset

More information

Lecture Summary CSC 263H. August 5, 2016

Lecture Summary CSC 263H. August 5, 2016 Lecture Summary CSC 263H August 5, 2016 This document is a very brief overview of what we did in each lecture, it is by no means a replacement for attending lecture or doing the readings. 1. Week 1 2.

More information

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016 CS125 Lecture 2 Fall 2016 2.1 Greedy Algorithms We will start talking about methods high-level plans for constructing algorithms. One of the simplest is just to have your algorithm be greedy. Being greedy,

More information

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29 Lecture 13 Connectedness in graphs Spanning trees in graphs Finding a minimal spanning tree Time costs of graph problems and NP-completeness Finding a minimal spanning tree: Prim s and Kruskal s algorithms

More information

Lecture Notes for Chapter 23: Minimum Spanning Trees

Lecture Notes for Chapter 23: Minimum Spanning Trees Lecture Notes for Chapter 23: Minimum Spanning Trees Chapter 23 overview Problem A town has a set of houses and a set of roads. A road connects 2 and only 2 houses. A road connecting houses u and v has

More information

CSE 521: Design and Analysis of Algorithms I

CSE 521: Design and Analysis of Algorithms I CSE 521: Design and Analysis of Algorithms I Greedy Algorithms Paul Beame 1 Greedy Algorithms Hard to define exactly but can give general properties Solution is built in small steps Decisions on how to

More information

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 4.5 Minimum Spanning Tree Minimum Spanning Tree Minimum spanning tree. Given a connected

More information

Minimum Spanning Trees and Prim s Algorithm

Minimum Spanning Trees and Prim s Algorithm Minimum Spanning Trees and Prim s Algorithm Version of October 3, 014 Version of October 3, 014 Minimum Spanning Trees and Prim s Algorithm 1 / 3 Outline Spanning trees and minimum spanning trees (MST).

More information

Lecture 6 Basic Graph Algorithms

Lecture 6 Basic Graph Algorithms CS 491 CAP Intro to Competitive Algorithmic Programming Lecture 6 Basic Graph Algorithms Uttam Thakore University of Illinois at Urbana-Champaign September 30, 2015 Updates ICPC Regionals teams will be

More information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms 6.046J/18.401J LECTURE 13 Graph algorithms Graph representation Minimum spanning trees Greedy algorithms Optimal substructure Greedy choice Prim s greedy MST algorithm Prof.

More information

Greedy algorithms. Given a problem, how do we design an algorithm that solves the problem? There are several strategies:

Greedy algorithms. Given a problem, how do we design an algorithm that solves the problem? There are several strategies: Greedy algorithms Input Algorithm Goal? Given a problem, how do we design an algorithm that solves the problem? There are several strategies: 1. Try to modify an existing algorithm. 2. Construct an algorithm

More information

Minimum Spanning Trees Ch 23 Traversing graphs

Minimum Spanning Trees Ch 23 Traversing graphs Next: Graph Algorithms Graphs Ch 22 Graph representations adjacency list adjacency matrix Minimum Spanning Trees Ch 23 Traversing graphs Breadth-First Search Depth-First Search 11/30/17 CSE 3101 1 Graphs

More information

Introduction to Algorithms

Introduction to Algorithms Introduction to Algorithms 6.046J/18.401J LECTURE 16 Greedy Algorithms (and Graphs) Graph representation Minimum spanning trees Optimal substructure Greedy choice Prim s greedy MST algorithm Prof. Charles

More information

Week 11: Minimum Spanning trees

Week 11: Minimum Spanning trees Week 11: Minimum Spanning trees Agenda: Minimum Spanning Trees Prim s Algorithm Reading: Textbook : 61-7 1 Week 11: Minimum Spanning trees Minimum spanning tree (MST) problem: Input: edge-weighted (simple,

More information

CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013

CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013 CSE373: Data Structures & Algorithms Lecture 7: Minimum Spanning Trees Dan Grossman Fall 03 Spanning Trees A simple problem: Given a connected undirected graph G=(V,E), find a minimal subset of edges such

More information

Lecture 13: Minimum Spanning Trees Steven Skiena

Lecture 13: Minimum Spanning Trees Steven Skiena Lecture 13: Minimum Spanning Trees Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.stonybrook.edu/ skiena Problem of the Day Your job

More information

Lecture 13: Minimum Spanning Trees Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY

Lecture 13: Minimum Spanning Trees Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY Lecture 13: Minimum Spanning Trees Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.sunysb.edu/ skiena Problem of the Day Your job is to

More information

Algorithms and Theory of Computation. Lecture 3: Graph Algorithms

Algorithms and Theory of Computation. Lecture 3: Graph Algorithms Algorithms and Theory of Computation Lecture 3: Graph Algorithms Xiaohui Bei MAS 714 August 20, 2018 Nanyang Technological University MAS 714 August 20, 2018 1 / 18 Connectivity In a undirected graph G

More information

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019 CS 341: Algorithms Douglas R. Stinson David R. Cheriton School of Computer Science University of Waterloo February 26, 2019 D.R. Stinson (SCS) CS 341 February 26, 2019 1 / 296 1 Course Information 2 Introduction

More information

Context: Weighted, connected, undirected graph, G = (V, E), with w : E R.

Context: Weighted, connected, undirected graph, G = (V, E), with w : E R. Chapter 23: Minimal Spanning Trees. Context: Weighted, connected, undirected graph, G = (V, E), with w : E R. Definition: A selection of edges from T E such that (V, T ) is a tree is called a spanning

More information

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 4.5 Minimum Spanning Tree Minimum Spanning Tree Minimum spanning tree. Given a connected

More information

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 4.5 Minimum Spanning Tree Minimum Spanning Tree Minimum spanning tree. Given a connected

More information

Minimum-Cost Spanning Tree. Example

Minimum-Cost Spanning Tree. Example Minimum-Cost Spanning Tree weighted connected undirected graph spanning tree cost of spanning tree is sum of edge costs find spanning tree that has minimum cost Example 2 4 12 6 3 Network has 10 edges.

More information

Minimum Spanning Trees

Minimum Spanning Trees Minimum Spanning Trees 04 6 33 135 49 PVD 1 40 146 61 JFK 14 15 0 111 34 Minimum Spanning Trees 1 Outline and Reading Minimum Spanning Trees Definitions A crucial fact The Prim-Jarnik Algorithm Kruskal's

More information

Minimum Spanning Trees

Minimum Spanning Trees Minimum Spanning Trees 04 6 33 49 PVD 1 40 146 61 14 15 0 Minimum Spanning Trees 1 Minimum Spanning Trees ( 1.) Spanning subgraph Subgraph of a graph G containing all the vertices of G Spanning tree 1

More information

Example. Minimum-Cost Spanning Tree. Edge Selection Greedy Strategies. Edge Selection Greedy Strategies

Example. Minimum-Cost Spanning Tree. Edge Selection Greedy Strategies. Edge Selection Greedy Strategies Minimum-Cost Spanning Tree weighted connected undirected graph spanning tree cost of spanning tree is sum of edge costs find spanning tree that has minimum cost Example 2 4 12 6 3 Network has 10 edges.

More information

Minimum Spanning Trees

Minimum Spanning Trees CS124 Lecture 5 Spring 2011 Minimum Spanning Trees A tree is an undirected graph which is connected and acyclic. It is easy to show that if graph G(V,E) that satisfies any two of the following properties

More information

For this graph, give its (a) adjacency matrix, (b) upper triangular adjacency matrix input format, (c) adjacency list, and (d) adjacency list input

For this graph, give its (a) adjacency matrix, (b) upper triangular adjacency matrix input format, (c) adjacency list, and (d) adjacency list input For this graph, give its (a) adjacency matrix, (b) upper triangular adjacency matrix input format, (c) adjacency list, and (d) adjacency list input format. 1 Assignment #4A is due on Fri. Nov. 15 at the

More information

Randomized Graph Algorithms

Randomized Graph Algorithms Randomized Graph Algorithms Vasileios-Orestis Papadigenopoulos School of Electrical and Computer Engineering - NTUA papadigenopoulos orestis@yahoocom July 22, 2014 Vasileios-Orestis Papadigenopoulos (NTUA)

More information

looking ahead to see the optimum

looking ahead to see the optimum ! Make choice based on immediate rewards rather than looking ahead to see the optimum! In many cases this is effective as the look ahead variation can require exponential time as the number of possible

More information

Minimum Spanning Trees

Minimum Spanning Trees Minimum Spanning Trees 04 6 33 135 49 1 40 146 61 14 15 0 111 34 Minimum Spanning Trees 1 Minimum Spanning Trees ( 1.) Spanning subgraph Subgraph of a graph G containing all the vertices of G Spanning

More information

Minimum Spanning Trees

Minimum Spanning Trees Minimum Spanning Trees Problem A town has a set of houses and a set of roads. A road connects 2 and only 2 houses. A road connecting houses u and v has a repair cost w(u, v). Goal: Repair enough (and no

More information

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved. Chapter 9 Greedy Technique Copyright 2007 Pearson Addison-Wesley. All rights reserved. Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that

More information

COP 4531 Complexity & Analysis of Data Structures & Algorithms

COP 4531 Complexity & Analysis of Data Structures & Algorithms COP 4531 Complexity & Analysis of Data Structures & Algorithms Lecture 8 Data Structures for Disjoint Sets Thanks to the text authors who contributed to these slides Data Structures for Disjoint Sets Also

More information

tree follows. Game Trees

tree follows. Game Trees CPSC-320: Intermediate Algorithm Design and Analysis 113 On a graph that is simply a linear list, or a graph consisting of a root node v that is connected to all other nodes, but such that no other edges

More information

CHAPTER 13 GRAPH ALGORITHMS

CHAPTER 13 GRAPH ALGORITHMS CHAPTER 13 GRAPH ALGORITHMS SFO LAX ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 00) AND SLIDES FROM NANCY

More information

Minimum Trees. The problem. connected graph G = (V,E) each edge uv has a positive weight w(uv)

Minimum Trees. The problem. connected graph G = (V,E) each edge uv has a positive weight w(uv) /16/015 Minimum Trees Setting The problem connected graph G = (V,E) each edge uv has a positive weight w(uv) Find a spanning graph T of G having minimum total weight T is a tree w T = w uv uv E(T) is minimal

More information

1 Minimum Cut Problem

1 Minimum Cut Problem CS 6 Lecture 6 Min Cut and Karger s Algorithm Scribes: Peng Hui How, Virginia Williams (05) Date: November 7, 07 Anthony Kim (06), Mary Wootters (07) Adapted from Virginia Williams lecture notes Minimum

More information

Partha Sarathi Manal

Partha Sarathi Manal MA 515: Introduction to Algorithms & MA5 : Design and Analysis of Algorithms [-0-0-6] Lecture 20 & 21 http://www.iitg.ernet.in/psm/indexing_ma5/y09/index.html Partha Sarathi Manal psm@iitg.ernet.in Dept.

More information

Graphs Weighted Graphs. Reading: 12.5, 12.6, 12.7

Graphs Weighted Graphs. Reading: 12.5, 12.6, 12.7 Graphs Weighted Graphs Reading: 1.5, 1.6, 1. Weighted Graphs, a.k.a. Networks In a weighted graph, each edge has an associated numerical value, called the weight or cost of the edge Edge weights may represent,

More information

CSE 100: GRAPH ALGORITHMS

CSE 100: GRAPH ALGORITHMS CSE 100: GRAPH ALGORITHMS Dijkstra s Algorithm: Questions Initialize the graph: Give all vertices a dist of INFINITY, set all done flags to false Start at s; give s dist = 0 and set prev field to -1 Enqueue

More information

Part VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths

Part VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths Part VI Graph algorithms Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths 1 Chapter 22 Elementary Graph Algorithms Representations of graphs

More information

CS 5321: Advanced Algorithms Minimum Spanning Trees. Acknowledgement. Minimum Spanning Trees

CS 5321: Advanced Algorithms Minimum Spanning Trees. Acknowledgement. Minimum Spanning Trees CS : Advanced Algorithms Minimum Spanning Trees Ali Ebnenasir Department of Computer Science Michigan Technological University Acknowledgement Eric Torng Moon Jung Chung Charles Ofria Minimum Spanning

More information

CS521 \ Notes for the Final Exam

CS521 \ Notes for the Final Exam CS521 \ Notes for final exam 1 Ariel Stolerman Asymptotic Notations: CS521 \ Notes for the Final Exam Notation Definition Limit Big-O ( ) Small-o ( ) Big- ( ) Small- ( ) Big- ( ) Notes: ( ) ( ) ( ) ( )

More information

Minimum Spanning Tree (5A) Young Won Lim 5/11/18

Minimum Spanning Tree (5A) Young Won Lim 5/11/18 Minimum Spanning Tree (5A) Copyright (c) 2015 2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2

More information

Union/Find Aka: Disjoint-set forest. Problem definition. Naïve attempts CS 445

Union/Find Aka: Disjoint-set forest. Problem definition. Naïve attempts CS 445 CS 5 Union/Find Aka: Disjoint-set forest Alon Efrat Problem definition Given: A set of atoms S={1, n E.g. each represents a commercial name of a drugs. This set consists of different disjoint subsets.

More information