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.
Minimum Spanning Tree CSE 331 Section 2 James Daly.
Chapter 3 The Greedy Method 3.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 13 Minumum spanning trees Motivation Properties of minimum spanning trees Kruskal’s.
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.
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.
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.
1 Minimum Spanning Tree Problem Topic 10 ITS033 – Programming & Algorithms Asst. Prof. Dr. Bunyarit Uyyanonvara IT Program, Image and Vision Computing.
SPANNING TREES Lecture 21 CS2110 – Spring
Minimum Spanning Trees
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
알고리즘 설계 및 분석 Foundations of Algorithm 유관우. Digital Media Lab. 2 Chap4. Greedy Approach Grabs data items in sequence, each time with “best” choice, without.
1 Greedy Algorithms and MST Dr. Ying Lu RAIK 283 Data Structures & Algorithms.
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.
Kruskal’s and Dijkstra’s Algorithm.  Kruskal's algorithm is an algorithm in graph theory that finds a minimum spanning tree for a connected weighted.
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.
MA/CSSE 473 Day 34 MST details: Kruskal's Algorithm Prim's Algorithm.
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
Design and Analysis of Algorithms - Chapter 91 Greedy algorithms Optimization problems solved through a sequence of choices that are: b feasible b locally.
Greedy Algorithms. Zhengjin,Central South University2 Review: Dynamic Programming Summary of the basic idea: Optimal substructure: optimal solution to.
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
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.
CISC 235: Topic 10 Graph Algorithms.
Short paths and spanning trees
Minimum-Cost Spanning Tree
CSCE350 Algorithms and Data Structure
Minimum Spanning Trees
Connected Components Minimum Spanning Tree
Minimum Spanning Tree.
Greedy Technique.
Minimum-Cost Spanning Tree
Minimum-Cost Spanning Tree
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,
MA/CSSE 473 Day 33 Student Questions Change to HW 13
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
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” edges (this is the greedy step)choose from “fringe” edges (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 Prim’s algorithm formally Algorithm Prim(G) V T  {v 0 } E T  { } for i  1 to |V|-1 do find a minimum weight edge e*=(v*,u*) among all the edges (v,u) such that v Є V T and u Є V-V T V T  V T ∪ {u*} E T  E T ∪ {e*} return E T

Design and Analysis of Algorithms - Chapter 97 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 Θ(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 98 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 99 Examples: a edc b

10 Kruskal’s algorithm Algorithm Kruskal(G) Sort E in nondecreasing order of the weights E T  { }; k  0; ecounter  0 while ecounter < |V|-1 k  k+1 if E T ∪ {e ik } is acyclic E T  E T ∪ {e ik } ecounter  ecounter + 1 return E T

Design and Analysis of Algorithms - Chapter 911 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 912 Shortest paths-Dijkstra’s algorithm b Single Source Shortest Paths Problem: Given a weighted graph G, find the shortest paths from a source vertex s to each of the other vertices. b Doesn’t work with negative weights b Applicable to both undirected and directed graphs

Design and Analysis of Algorithms - Chapter 913 Shortest paths-Dijkstra’s algorithm 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 914 Example: a edc b

Design and Analysis of Algorithms - Chapter 915 Dijkstra’s algorithm Algorithm Dijkstra(G,s) Initialize(Q) for every vertex v Є V do d v  ∞; p v  null; Insert(Q,v, d v ) d s  0; Decrease(Q,s,d s ); V T  0 for i  0 to |V|-1 do u*  DeleteMin(Q); V T  V T ∪ {u*} for every vertex u in V-V T that is adjacent to u* do if d u* +w(u*,u)<d u d u  d u +w(u*,u); p u  u*; Decrease(Q,u,d u ) b Efficiency: