Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.

Slides:



Advertisements
Similar presentations
Chapter 9 Greedy Technique. Constructs a solution to an optimization problem piece by piece through a sequence of choices that are: b feasible - b feasible.
Advertisements

Lecture 15. Graph Algorithms
Chapter 23 Minimum Spanning Tree
Comp 122, Spring 2004 Greedy Algorithms. greedy - 2 Lin / Devi Comp 122, Fall 2003 Overview  Like dynamic programming, used to solve optimization problems.
Greedy Algorithms Greed is good. (Some of the time)
Greed is good. (Some of the time)
1 Minimum Spanning Tree Prim-Jarnik algorithm Kruskal algorithm.
1 Spanning Trees Lecture 20 CS2110 – Spring
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Tree tree = connected graph with no cycle tree = connected graph with |V|-1 edges tree = graph with |V|-1 edges and no cycles.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
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.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Lecture 12 Minimum Spanning Tree. Motivating Example: Point to Multipoint Communication Single source, Multiple Destinations Broadcast – All nodes in.
Minimum Spanning Trees CIS 606 Spring Problem A town has a set of houses and a set of roads. A road connects 2 and only 2 houses. A road connecting.
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.
Design and Analysis of Algorithms 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.
Data Structures and Algorithms Graphs Minimum Spanning Tree PLSD210.
Minimal Spanning Trees What is a minimal spanning tree (MST) and how to find one.
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
Analysis of Algorithms
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
SPANNING TREES Lecture 21 CS2110 – Spring
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
Spring 2015 Lecture 11: Minimum Spanning Trees
Prims’ spanning tree algorithm Given: connected graph (V, E) (sets of vertices and edges) V1= {an arbitrary node of V}; E1= {}; //inv: (V1, E1) is a tree,
Spanning Trees CSIT 402 Data Structures II 1. 2 Two Algorithms Prim: (build tree incrementally) – Pick lower cost edge connected to known (incomplete)
Lectures on Greedy Algorithms and Dynamic Programming
November 13, Algorithms and Data Structures Lecture XII Simonas Šaltenis Aalborg University
Union-Find  Application in Kruskal’s Algorithm  Optimizing Union and Find Methods.
1 Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that are: b feasible b locally optimal.
SPANNING TREES Lecture 20 CS2110 – Fall Spanning Trees  Definitions  Minimum spanning trees  3 greedy algorithms (incl. Kruskal’s & Prim’s)
SPANNING TREES Lecture 21 CS2110 – Fall Nate Foster is out of town. NO 3-4pm office hours today!
Minimum Spanning Trees CSE 373 Data Structures Lecture 21.
MA/CSSE 473 Day 34 MST details: Kruskal's Algorithm Prim's Algorithm.
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
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.
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
Minimum Spanning Trees
Minimum Spanning Tree Chapter 13.6.
Lecture 22 Minimum Spanning Tree
Minimum Spanning Trees
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Data Structures & Algorithms Graphs
Minimum-Cost Spanning Tree
CSCE350 Algorithms and Data Structure
Minimum Spanning Tree.
Connected Components Minimum Spanning Tree
Minimum Spanning Tree.
Minimum Spanning Tree.
Minimum-Cost Spanning Tree
Greedy Algorithm (17.4/16.4) Greedy Algorithm (GA)
Chapter 23 Minimum Spanning Tree
Minimum-Cost Spanning Tree
Autumn 2015 Lecture 10 Minimum Spanning Trees
Graph Searching.
Minimum Spanning Trees
Minimum Spanning Tree.
Minimum Spanning Trees
Autumn 2016 Lecture 10 Minimum Spanning Trees
Minimum Spanning Trees (MSTs)
Spanning Trees Lecture 20 CS2110 – Spring 2015.
Winter 2019 Lecture 10 Minimum Spanning Trees
Lecture 14 Minimum Spanning Tree (cont’d)
Prims’ spanning tree algorithm
Minimum-Cost Spanning Tree
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem

Example: Coin Changing Problem Give change using the minimum number of coins. Greedy approach: always use larger coins first Example when it doesn’t work: 16c due, coins of 12, 10, 5 and 1. Greedy: 12, 1, 1, 1, 1 Optimal: 10, 5, 1 Moral: need to prove that greedy produces optimal

Greedy Algorithm Applies to Optimization Problems (find minimum or maximum such that…) Strategy: construct the solution by choosing elements one at a time in a greedy fashion (local optimum item), hoping that it will produce the global optimum structure.

Minimum Spanning Tree Given undirected connected weighted graph (“costs” assigned to edges). Spanning tree: minimum connected subgraph Minimum weight (or cost) spanning tree: sum over all edges is minimum over all possible spanning trees

Optimum Spanning Tree Minimum Maximum

Naïve Solution Enumerate all trees, compute their costs Find minimum (resp. maximum) Why bad? Number of trees on n vertices is very large (exponential): n n-2. Hence number of spanning trees can be very large => inefficient algorithm (exponential)

Greedy Algorithms for MST Prim’s algorithm: start with some vertex v. At next step, choose the minimum edge adjacent to already constructed tree, while maintaining the tree property Kruskal’s algorithm: sort edges in increasing order, add one at a time while maintaining forest property

Prim’s Algorithm for MST

Prim’s Algorithm: Invariant At each step maintain a tree Compute fringe: list of all edges out of the current tree Find minimum edge in the fringe Add it to the tree

Prim’s Algorithm: Analysis At each step add a vertex: n steps Compute fringe: list of all edges out of the current tree Find minimum edge in the fringe: O(m) Add it to the tree Total: O(nm) Naive

Prim’s Algorithm: Better Implementation and Analysis At each step add a vertex: n steps Compute fringe: list of all edges out of the current tree, keep as heap. Must look at all edges O(m) Find minimum edge in the fringe: O(log m) = O(log n) Add it to the tree Total: O(m+nlog n)

Kruskal’s Algorithm for MST Sort all edges O(m 2 log n) At each step, choose the next min weight edge from the list that does not create a cycle. Invariant: maintain a forest of the min weight edges encountered up to step k

Kruskal’s Algorithm for MST

Kruskal’s Algorithm for MST: forest along the way

Kruskal’s Algorithm for MST: Analysis Sort all edges O(m 2 log n) At each step, choose the next min weight edge from the list that does not create a cycle: O(log n). Total n-1 steps Total: O(m 2 log n)

Correctness Must prove that the greedy strategy produces the optimum solution Prim: show that if the min edge is not chosen at some step k, then it is not a MST (there exists a tree of smaller cost) Kruskal: show that min edge must be in MST; then next one, and next one etc.

Correctness of Prim’s Algorithm Assume MST unique By contradiction. Show that if the min fringe edge is not chosen at some step k, then it is not a MST (there exists a tree of smaller cost)

Prim’s Algorithm: Correctness Assume turquoise tree is MST but does not use red edge (min at this step) Red edge forms a cycle with tree edges, with at least one other edge in the fringe Removing this edge of the cycle and putting back the red edge creates a smaller cost tree Contradiction