Design and Analysis of Algorithms - Chapter 91 Greedy algorithms Optimization problems solved through a sequence of choices that are: b feasible b locally.

Slides:



Advertisements
Similar presentations
Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that are: feasible, i.e. satisfying the.
Advertisements

Greedy Technique The first key ingredient is the greedy-choice property: a globally optimal solution can be arrived at by making a locally optimal (greedy)
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.
Lecture 15. Graph Algorithms
Greedy Algorithms Greed is good. (Some of the time)
Greed is good. (Some of the time)
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Chapter 4 The Greedy Approach. Minimum Spanning Tree A tree is an acyclic, connected, undirected graph. A spanning tree for a given graph G=, where E.
Chapter 3 The Greedy Method 3.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Design and Analysis of Algorithms - Chapter 91 Greedy algorithms Optimization problems solved through a sequence of choices that are: b feasible b locally.
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)
Chapter 9 Greedy Technique Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
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.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
TECH Computer Science Graph Optimization Problems and Greedy Algorithms Greedy Algorithms  // Make the best choice now! Optimization Problems  Minimizing.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each decision is locally optimal. These.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
SPANNING TREES Lecture 21 CS2110 – Spring
Minimum Spanning Trees
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 9 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
1 Minimum Spanning Trees (some material adapted from slides by Peter Lee, Ananda Guna, Bettina Speckmann)
Minimum Spanning Trees CS 146 Prof. Sin-Min Lee Regina Wang.
CSCE350 Algorithms and Data Structure Lecture 19 Jianjun Hu Department of Computer Science and Engineering University of South Carolina
1 Prim’s algorithm. 2 Minimum Spanning Tree Given a weighted undirected graph G, find a tree T that spans all the vertices of G and minimizes the sum.
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)
Theory of Algorithms: Greedy Techniques James Gain and Edwin Blake {jgain | Department of Computer Science University of Cape Town.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
MA/CSSE 473 Day 34 MST details: Kruskal's Algorithm Prim's Algorithm.
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
Greedy Algorithms. Zhengjin,Central South University2 Review: Dynamic Programming Summary of the basic idea: Optimal substructure: optimal solution to.
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.
Minimum Spanning Trees
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that are: feasible locally optimal irrevocable.
Chapter 5 : Trees.
Greedy Technique.
Greedy function greedy { S <- S0 //Initialization
Minimum Spanning Tree Chapter 13.6.
Minimum Spanning Trees and Shortest Paths
Short paths and spanning trees
Data Structures & Algorithms Graphs
Minimum-Cost Spanning Tree
CSCE350 Algorithms and Data Structure
Minimum Spanning Tree.
Minimum Spanning Trees
Connected Components Minimum Spanning Tree
Minimum Spanning Tree.
Greedy Technique.
Minimum-Cost Spanning Tree
Minimum-Cost Spanning Tree
MA/CSSE 473 Day 33 Student Questions Change to HW 13
Minimum Spanning Trees
Autumn 2016 Lecture 10 Minimum Spanning Trees
Spanning Trees Lecture 20 CS2110 – Spring 2015.
Greedy Algorithms (I) Greed, for lack of a better word, is good! Greed is right! Greed works! - Michael Douglas, U.S. actor in the role of Gordon Gecko,
Minimum-Cost Spanning Tree
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Design and Analysis of Algorithms - Chapter 91 Greedy algorithms Optimization problems solved through a sequence of choices that are: b feasible b locally optimal b irrevocable Not all optimization problems can be approached in this manner!

Design and Analysis of Algorithms - Chapter 92 Applications of the Greedy Strategy b Optimal solutions: change makingchange making Minimum Spanning Tree (MST)Minimum Spanning Tree (MST) Single-source shortest pathsSingle-source shortest paths simple scheduling problemssimple scheduling problems Huffman codesHuffman codes b Approximations: Traveling Salesman Problem (TSP)Traveling Salesman Problem (TSP) Knapsack problemKnapsack problem other combinatorial optimization problemsother combinatorial optimization problems

Design and Analysis of Algorithms - Chapter 93 Minimum Spanning Tree (MST) b Spanning tree of a connected graph G: a connected acyclic subgraph of G that includes all of G’s vertices. b Minimum Spanning Tree of a weighted, connected graph G: a spanning tree of G of minimum total weight. b Example:

Design and Analysis of Algorithms - Chapter 94 Prim’s MST algorithm b Start with tree consisting of one vertex b “grow” tree one vertex/edge at a time to produce MST Construct a series of expanding subtrees T 1, T 2, …Construct a series of expanding subtrees T 1, T 2, … b at each stage construct T i+1 from T i : add minimum weight edge connecting a vertex in tree (T i ) to one not yet in tree choose from “fringe” edgeschoose from “fringe” edges (this is the “greedy” step!)(this is the “greedy” step!) b algorithm stops when all vertices are included

Design and Analysis of Algorithms - Chapter 95 Examples: a edc b

6 Notes about Prim’s algorithm b Need to prove that this construction actually yields MST b Need priority queue for locating lowest cost fringe edge: use min-heap b Efficiency: For graph with n vertices and m edges: (n – 1 + m) log n (n – 1 + m) log n Θ(m log n) Θ(m log n) number of stages (min-heap deletions) number of edges considered (min-heap insertions) insertion/deletion from min-heap

Design and Analysis of Algorithms - Chapter 97 Another Greedy algorithm for MST: Kruskal b Start with empty forest of trees b “grow” MST one edge at a time intermediate stages usually have forest of trees (not connected)intermediate stages usually have forest of trees (not connected) b at each stage add minimum weight edge among those not yet used that does not create a cycle edges are initially sorted by increasing weightedges are initially sorted by increasing weight at each stage the edge may:at each stage the edge may: –expand an existing tree –combine two existing trees into a single tree –create a new tree need efficient way of detecting/avoiding cyclesneed efficient way of detecting/avoiding cycles b algorithm stops when all vertices are included

Design and Analysis of Algorithms - Chapter 98 Examples: a edc b

9 Notes about Kruskal’s algorithm b Algorithm looks easier than Prim’s but is harder to implement (checking for cycles!)harder to implement (checking for cycles!) less efficient Θ(m log m)less efficient Θ(m log m) b Cycle checking: a cycle exists iff edge connects vertices in the same component. b Union-find algorithms – see section 9.2

Design and Analysis of Algorithms - Chapter 910 Shortest paths-Dijkstra’s algorithm b Single Source Shotest Paths Problem: Given a weighted graph G, find the shortest paths from a source vertex s to each of the other vertices. b Dijkstra’s algorithm: Similar to Prim’s MST algorithm, with the following difference: Start with tree consisting of one vertexStart with tree consisting of one vertex “grow” tree one vertex/edge at a time to produce MST“grow” tree one vertex/edge at a time to produce MST –Construct a series of expanding subtrees T 1, T 2, … Keep track of shortest path from source to each of the vertices in T iKeep track of shortest path from source to each of the vertices in T i at each stage construct T i+1 from T i : add minimum weight edge connecting a vertex in tree (T i ) to one not yet in treeat each stage construct T i+1 from T i : add minimum weight edge connecting a vertex in tree (T i ) to one not yet in tree –choose from “fringe” edges –(this is the “greedy” step!) algorithm stops when all vertices are includedalgorithm stops when all vertices are included edge (v,w) with lowest d(s,v) + d(v,w)

Design and Analysis of Algorithms - Chapter 911 Example: a edc b

Design and Analysis of Algorithms - Chapter 912 Notes on Dijkstra’s algorithm b Doesn’t work with negative weights b Applicable to both undirected and directed graphs b Efficiency: