Introduction: (Edge-)Weighted Graph

Size: px
Start display at page:

Download "Introduction: (Edge-)Weighted Graph"

Transcription

1 Introduction: (Edge-)Weighted Graph c 8 7 a b 7 i d 9 e 8 h 6 f 0 g These are computers and costs of direct connections. What is a cheapest way to network them? / 8

2 (Edge-)Weighted Graph Many useful graphs have numbers assigned to edges. Think of: each edge has a price tag. (Usually 0. Some cases have < 0.) A weighted (edge-weighted) graph consists of: a set of vertices a set of edges weights: a map from edges to numbers if undirected graph: {u, v} = {v, u}, same weight if directed graph: (u, v) and (v, u) may have different weights Notation: w(u, v) or weight(u, v). / 8

3 Storing a Weighted Graph C E A B 5 D Adjacency matrix: Adjacency lists: A B C D E A 0 B 0 5 C 0 D 5 0 E 0 A B C D E adjacency list (B,), (C,) (A,), (C,), (D,5) (A,), (B,) (B,5) 3 / 8

4 Common Task # on Weighted Graphs Minimum spanning tree: Find a spanning tree. Minimize the sum of the weights of the edges used. C A B 5 D Usually just for undirected, connected graphs. / 8

5 Kruskal s Algorithm: Idea Kruskal s algorithm finds a minimum spanning tree by successive mergers.. At first, each vertex is its own small cluster (tree/set in textbook).. Find an edge of minimum weight, use it to merge two clusters into one. 3. Do it again.... In general, find an edge of minimum weight that crosses two clusters; merge them into one. So each iteration you find a cheapest way to merge two trees. (Not a correctness proof, but a good hint.) 5 / 8

6 Kruskal s Algorithm: A Few Example Steps c 8 7 a b 7 i d 9 e 8 h 6 f 0 g 6 / 8

7 Kruskal s Algorithm: A Few Example Steps c 8 7 a b 7 i d 9 e 8 h 6 f 0 g 6 / 8

8 Kruskal s Algorithm: A Few Example Steps c 8 7 a b 7 i d 9 e 8 h 6 f 0 g 6 / 8

9 Kruskal s Algorithm: A Few Example Steps c 8 7 a b 7 i d 9 e 8 h 6 f 0 g 6 / 8

10 Kruskal s Algorithm: A Few Example Steps c 8 7 a b 7 i d 9 e 8 h 6 f 0 g 6 / 8

11 Kruskal s Algorithm: A Few Example Steps c 8 7 a b 7 i d 9 e 8 h 6 f 0 g 6 / 8

12 Kruskal s Algorithm A := new container() for chosen edges L := list of edges sorted in increasing weights for each vertex v: v.cluster := {v} for each {u, v} in L in order: if u.cluster v.cluster: A.add({u, v}) merge u.cluster and v.cluster return A 7 / 8

13 Storing Clusters: Easy Way each cluster is a linked list v.cluster is pointer to v s owning linked list u.cluster v.cluster is pointer equality, Θ() time merging two clusters is merging two linked lists, BUT: a lot of vertices need their v.cluster s updated Luckily, if you move the smaller list to the larger one, then: whenever v.cluster needs update, cluster size doubles each v.cluster is updated at most lg V times, ever A much faster way will appear later in this course. 8 / 8

14 Kruskal s Algorithm Time Collecting and sorting edges: Θ( E lg E ). v.cluster updates: O(lg V ) per vertex the rest is Θ() per vertex or edge Total O( V lg V + E lg E ) time worst case. Note lg E O(lg V ). O(( V + E ) lg V ) time. Faster if faster cluster implementation. 9 / 8

15 Prim s Algorithm: Idea Prim s algorithm finds a minimum spanning tree by growing the tree around the starting vertex, successively adding the next cheapest edge that links up one more vertex. This is like how breadth-first search grows a breadth-first tree, but with a twist: The queue is changed to a min priority queue. Priority of vertex v = smallest seen edge weight between v and the tree so far. ( if no such edge.) So every time you extract-min, you get a cheapest edge to add to the tree. (Not a correctness proof, but a good hint.) 0 / 8

16 Prim s Algorithm: A Few Example Steps c 8 7 a b 7 i d 9 e 8 h 6 f 0 g vertex a b c d e f g h i priority 0 pred / 8

17 Prim s Algorithm: A Few Example Steps c 8 7 a b 7 i d 9 e 8 h 6 f 0 g vertex b h c d e f g i priority 8 pred a a / 8

18 Prim s Algorithm: A Few Example Steps c 8 7 a b 7 i d 9 e 8 h 6 f 0 g vertex h c d e f g i priority 8 8 pred a b / 8

19 Prim s Algorithm: A Few Example Steps c 8 7 a b 7 i d 9 e 8 h 6 f 0 g vertex g i c d e f priority 7 8 pred h h b / 8

20 Prim s Algorithm: A Few Example Steps c 8 7 a b 7 i d 9 e 8 h 6 f 0 g vertex f i c d e priority 6 8 pred g g b / 8

21 Prim s Algorithm: A Few Example Steps c 8 7 a b 7 i d 9 e 8 h 6 f 0 g vertex c i e d priority 6 0 pred f g f f / 8

22 Prim s Algorithm A := new container() for chosen edges Q := new min-heap() start := pick a vertex Q.insert(start, 0) for each vertex v start: Q.insert(v, ) while Q not empty: u := Q.extract-min() A.add({u.pred, u}) for each z in u s adjacency list: if z in Q && weight(u, z) < priority of z: Q.decrease-priority(z, weight(u, z)) z.pred := u return A / 8

23 Prim s Algorithm Time every vertex enters and leaves min-heap once: Θ(lg V ) each every edge may trigger a change of priority: O(lg V ) each the rest can be done in Θ() per vertex or per edge (need clever coding) Total O(( V + E ) lg V ) time worst case. 3 / 8

24 Prim s Correctness Sketch Loop invariant:. A some MST T. A spans finished vertices (outside Q) 3. What I said about vertex priorities. Why the loop body maintains # and #3: Exercise. Why the loop body maintains #: Let p = u.pred. The loop body adds {p, u} to A. Let A = A {{p, u}}. A some MST T because: If T has {p, u}, then choose T = T. Else, next slide... Can replace some edge by {p, u}. / 8

25 Prim s Correctness Sketch If T does not have {p, u}: T has a unique simple path from p (finished) to u ( Q), via some edge {x, y} with x finished and y Q. T without {x, y} would break apart; {p, u} would reconnect. {p, u} is as cheap as {x, y} because u is fresh off Q.extract-min: weight(p, u) = priority(u) priority(y) weight(x, y) Choose T = T {{x, y}} {{p, u}}, still MST, A T. 5 / 8

26 Kruskal s Correctness Sketch Loop invariant:. A some MST T.. Clusters correspond to trees in A. Why the loop body maintains #: {u, v} is a cheapest edge that can glue two clusters. The loop body adds {u, v} to A. Let A = A {{u, v}}. A some MST T because: If T has {u, v}, then choose T = T. Else, next slide... Can replace some edge by {u, v}. 6 / 8

27 Kruskal s Correctness Sketch If T does not have {u, v}: Partition V into S and V S such that: No edge in A goes across. So no cluster goes across. u s cluster on S side, v s cluster on V S side. T has a unique simple path from u ( S) to v ( S), via some edge {x, y} with x S and y S. T without {x, y} would break apart; {u, v} would reconnect. {x, y} can glue two clusters. {u, v} is a cheapest edge that can glue two clusters. So {u, v} is as cheap as {x, y}. Choose T = T {{x, y}} {{u, v}}, still MST, A T. 7 / 8

28 General Theorem Suppose: A some MST T Can partition V into S and V S such that: No edge in A goes across. {u, v} is a cheapest edge going across. Then A {{u, v}} some MST T. Proof sketch: If T does not have {u, v}: T has a unique simple path from u to v, via some edge {x, y} going across S to V S. T without {x, y} would break apart; {u, v} would reconnect. {u, v} is as cheap as {x, y}. Choose T = T {{x, y}} {{u, v}}. 8 / 8

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 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

Algorithms and Data Structures: Minimum Spanning Trees I and II - Prim s Algorithm. ADS: lects 14 & 15 slide 1

Algorithms and Data Structures: Minimum Spanning Trees I and II - Prim s Algorithm. ADS: lects 14 & 15 slide 1 Algorithms and Data Structures: Minimum Spanning Trees I and II - Prim s Algorithm ADS: lects 14 & 15 slide 1 Weighted Graphs Definition 1 A weighted (directed or undirected graph) is a pair (G, W ) consisting

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

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

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

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

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

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

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

CSE 100 Minimum Spanning Trees Prim s and Kruskal

CSE 100 Minimum Spanning Trees Prim s and Kruskal CSE 100 Minimum Spanning Trees Prim s and Kruskal Your Turn The array of vertices, which include dist, prev, and done fields (initialize dist to INFINITY and done to false ): V0: dist= prev= done= adj:

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

Week 12: Minimum Spanning trees and Shortest Paths

Week 12: Minimum Spanning trees and Shortest Paths Agenda: Week 12: Minimum Spanning trees and Shortest Paths Kruskal s Algorithm Single-source shortest paths Dijkstra s algorithm for non-negatively weighted case Reading: Textbook : 61-7, 80-87, 9-601

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

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

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

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

CS/COE

CS/COE CS/COE 1501 www.cs.pitt.edu/~lipschultz/cs1501/ Weighted Graphs Last time, we said spatial layouts of graphs were irrelevant We define graphs as sets of nodes and edges However, we ll certainly want to

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

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

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee Algorithm Analysis Graph algorithm Chung-Ang University, Jaesung Lee Basic definitions Graph = (, ) where is a set of vertices and is a set of edges Directed graph = where consists of ordered pairs

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

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

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

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

Depth-first Search (DFS)

Depth-first Search (DFS) Depth-first Search (DFS) DFS Strategy: First follow one path all the way to its end, before we step back to follow the next path. (u.d and u.f are start/finish time for vertex processing) CH08-320201:

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

CSC 1700 Analysis of Algorithms: Minimum Spanning Tree

CSC 1700 Analysis of Algorithms: Minimum Spanning Tree CSC 1700 Analysis of Algorithms: Minimum Spanning Tree Professor Henry Carter Fall 2016 Recap Space-time tradeoffs allow for faster algorithms at the cost of space complexity overhead Dynamic programming

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya CS60020: Foundations of Algorithm Design and Machine Learning Sourangshu Bhattacharya Graphs (review) Definition. A directed graph (digraph) G = (V, E) is an ordered pair consisting of a set V of vertices

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

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

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

Weighted Graph Algorithms Presented by Jason Yuan

Weighted Graph Algorithms Presented by Jason Yuan Weighted Graph Algorithms Presented by Jason Yuan Slides: Zachary Friggstad Programming Club Meeting Weighted Graphs struct Edge { int u, v ; int w e i g h t ; // can be a double } ; Edge ( int uu = 0,

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

CSC 8301 Design & Analysis of Algorithms: Kruskal s and Dijkstra s Algorithms

CSC 8301 Design & Analysis of Algorithms: Kruskal s and Dijkstra s Algorithms CSC 8301 Design & Analysis of Algorithms: Kruskal s and Dijkstra s Algorithms Professor Henry Carter Fall 2016 Recap Greedy algorithms iterate locally optimal choices to construct a globally optimal solution

More information

Algorithms and Data Structures (INF1) Lecture 15/15 Hua Lu

Algorithms and Data Structures (INF1) Lecture 15/15 Hua Lu Algorithms and Data Structures (INF1) Lecture 15/15 Hua Lu Department of Computer Science Aalborg University Fall 2007 This Lecture Minimum spanning trees Definitions Kruskal s algorithm Prim s algorithm

More information

CSci 231 Final Review

CSci 231 Final Review CSci 231 Final Review Here is a list of topics for the final. Generally you are responsible for anything discussed in class (except topics that appear italicized), and anything appearing on the homeworks.

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

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

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

Spanning Tree. Lecture19: Graph III. Minimum Spanning Tree (MSP)

Spanning Tree. Lecture19: Graph III. Minimum Spanning Tree (MSP) Spanning Tree (015) Lecture1: Graph III ohyung Han S, POSTH bhhan@postech.ac.kr efinition and property Subgraph that contains all vertices of the original graph and is a tree Often, a graph has many different

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2015S-18 Spanning Trees David Galles Department of Computer Science University of San Francisco 18-0: Spanning Trees Given a connected, undirected graph G A subgraph

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

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

Module 5 Graph Algorithms

Module 5 Graph Algorithms Module 5 Graph lgorithms Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS 97 E-mail: natarajan.meghanathan@jsums.edu 5. Graph Traversal lgorithms Depth First

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

Greedy Algorithms. Previous Examples: Huffman coding, Minimum Spanning Tree Algorithms

Greedy Algorithms. Previous Examples: Huffman coding, Minimum Spanning Tree Algorithms Greedy Algorithms A greedy algorithm is one where you take the step that seems the best at the time while executing the algorithm. Previous Examples: Huffman coding, Minimum Spanning Tree Algorithms Coin

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

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

COMP 182: Algorithmic Thinking Prim and Dijkstra: Efficiency and Correctness

COMP 182: Algorithmic Thinking Prim and Dijkstra: Efficiency and Correctness Prim and Dijkstra: Efficiency and Correctness Luay Nakhleh 1 Prim s Algorithm In class we saw Prim s algorithm for computing a minimum spanning tree (MST) of a weighted, undirected graph g. The pseudo-code

More information

Complexity of Prim s Algorithm

Complexity of Prim s Algorithm The main loop is: Complexity of Prim s Algorithm while ( not ISEMPTY(Q) ): u = EXTRACT-MIN(Q) if p[u]!= NIL: A = A U {(p[u],u)} for v in adjacency-list[u]: if v in Q and w(u,v) < priority[v] : DECREASE-PRIORITY(v,

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

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 018 D/Q Greed SP s DP LP, Flow B&B, Backtrack Metaheuristics P, NP Design and Analysis of Algorithms Lecture 8: Greed Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Optimization

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 10 Implementing MST Algorithms Adam Smith Minimum spanning tree (MST) Input: A connected undirected graph G = (V, E) with weight function w : E R. For now, assume

More information

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

CS 561, Lecture 10. Jared Saia University of New Mexico CS 561, Lecture 10 Jared Saia University of New Mexico Today s Outline The path that can be trodden is not the enduring and unchanging Path. The name that can be named is not the enduring and unchanging

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

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

CS61B, Fall 2002 Discussion #15 Amir Kamil UC Berkeley 12/5/02

CS61B, Fall 2002 Discussion #15 Amir Kamil UC Berkeley 12/5/02 CS61B, Fall 2002 Discussion #15 Amir Kamil UC Berkeley 12/5/02 Topics: Graph Algorithms 1 Graph Algorithms There are many algorithms that can be applied to graphs. Many of these are actually used in the

More information

Greedy algorithms is another useful way for solving optimization problems.

Greedy algorithms is another useful way for solving optimization problems. Greedy Algorithms Greedy algorithms is another useful way for solving optimization problems. Optimization Problems For the given input, we are seeking solutions that must satisfy certain conditions. These

More information

Lecture 11: Analysis of Algorithms (CS ) 1

Lecture 11: Analysis of Algorithms (CS ) 1 Lecture 11: Analysis of Algorithms (CS583-002) 1 Amarda Shehu November 12, 2014 1 Some material adapted from Kevin Wayne s Algorithm Class @ Princeton 1 2 Dynamic Programming Approach Floyd-Warshall Shortest

More information

Minimum spanning trees

Minimum spanning trees CE 367R MINIMUM SPANNING TREES Minimum Spanning Tree Identify a subset of links which form a spanning tree (connecting all nodes), where the total cost of the links in the tree is minimized. Minimum Spanning

More information

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 Asymptotics, Recurrence and Basic Algorithms 1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 1. O(logn) 2. O(n) 3. O(nlogn) 4. O(n 2 ) 5. O(2 n ) 2. [1 pt] What is the solution

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

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

COS 226 Lecture 19: Minimal Spanning Trees (MSTs) PFS BFS and DFS examples. Classic algorithms for solving a natural problem

COS 226 Lecture 19: Minimal Spanning Trees (MSTs) PFS BFS and DFS examples. Classic algorithms for solving a natural problem COS Lecture 9: Minimal Spanning Trees (MSTs) PFS BFS and DFS examples Classic algorithms for solving a natural problem MINIMAL SPANNING TREE Kruskal s algorithm Prim s algorithm Boruvka s algorithm Long

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

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

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

( D. Θ n. ( ) f n ( ) D. Ο%

( D. Θ n. ( ) f n ( ) D. Ο% CSE 0 Name Test Spring 0 Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to run the code below is in: for i=n; i>=; i--) for j=; j

More information

Outline and Reading. Minimum Spanning Tree. Minimum Spanning Tree. Cycle Property. Minimum Spanning Trees ( 12.7)

Outline and Reading. Minimum Spanning Tree. Minimum Spanning Tree. Cycle Property. Minimum Spanning Trees ( 12.7) Outline and Reading Minimum Spanning Tree PV 1 1 1 1 JK 1 15 SO 11 1 LX 15 Minimum Spanning Trees ( 1.) efinitions crucial fact Prim-Jarnik s lgorithm ( 1..) Kruskal s lgorithm ( 1..1) 111 // :1 PM Minimum

More information

Introduction to Algorithms. Lecture 11

Introduction to Algorithms. Lecture 11 Introduction to Algorithms Lecture 11 Last Time Optimization Problems Greedy Algorithms Graph Representation & Algorithms Minimum Spanning Tree Prim s Algorithm Kruskal s Algorithm 2 Today s Topics Shortest

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

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

Chapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1

Chapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs 2011 Pearson Addison-Wesley. All rights reserved 14 A-1 Terminology G = {V, E} A graph G consists of two sets A set V of vertices, or nodes A set E of edges A subgraph Consists of a subset

More information

Solutions to relevant spring 2000 exam problems

Solutions to relevant spring 2000 exam problems Problem 2, exam Here s Prim s algorithm, modified slightly to use C syntax. MSTPrim (G, w, r): Q = V[G]; for (each u Q) { key[u] = ; key[r] = 0; π[r] = 0; while (Q not empty) { u = ExtractMin (Q); for

More information

Pred 8 1. Dist. Pred

Pred 8 1. Dist. Pred CS Graph Algorithms, Page Shortest Path Problem Task: given a graph G, find the shortest path from a vertex u to a vertex v. ffl If all edges are of the same length, then BFS will do. ffl But some times

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

CSE 5311 Notes 8: Minimum Spanning Trees

CSE 5311 Notes 8: Minimum Spanning Trees CSE Notes 8: Minimum Spanning Trees (Last updated /8/7 :0 PM) CLRS, Chapter CONCEPTS Given a weighted, connected, undirected graph, find a minimum (total) weight free tree connecting the vertices. (AKA

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

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

CISC 320 Midterm Exam

CISC 320 Midterm Exam Name: CISC 320 Midterm Exam Wednesday, Mar 25, 2015 There are 19 questions. The first 15 questions count 4 points each. For the others, points are individually shown. The total is 100 points. Multiple

More information