Design & Analysis of Algorithm Greedy Algorithm

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

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.
Greedy Algorithms.
Greedy Algorithms Greed is good. (Some of the time)
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.
Lecture 3: Greedy Method Greedy Matching Coin Changing Minimum Spanning Tree Fractional Knapsack Dijkstra's Single-Source Shortest-Path.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
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.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Chapter 9 Greedy Technique Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Design and Analysis of Algorithms Minimum Spanning trees
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Algorithms: Design and Analysis Summer School 2013 at VIASM: Random Structures and Algorithms Lecture 3: Greedy algorithms Phan Th ị Hà D ươ ng 1.
Lecture 12-2: Introduction to Computer Algorithms beyond Search & Sort.
Informatics Department Parahyangan Catholic University D ESIGN & A NALYSIS OF A LGORITHM 12 – G REEDY A LGORITHM.
알고리즘 설계 및 분석 Foundations of Algorithm 유관우. Digital Media Lab. 2 Chap4. Greedy Approach Grabs data items in sequence, each time with “best” choice, without.
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.
CSCI 256 Data Structures and Algorithm Analysis Lecture 6 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
Greedy Algorithms. What is “Greedy Algorithm” Optimization problem usually goes through a sequence of steps A greedy algorithm makes the choice looks.
Minimum Spanning Trees CS 146 Prof. Sin-Min Lee Regina Wang.
December 14, 2015 Design and Analysis of Computer Algorithm Pradondet Nilagupta Department of Computer Engineering.
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.
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 General principle of greedy algorithm
Greedy Algorithms.
CSCE 411 Design and Analysis of Algorithms
COMP108 Algorithmic Foundations Greedy methods
Lecture on Design and Analysis of Computer Algorithm
Greedy Technique.
Greedy function greedy { S <- S0 //Initialization
Chapter 5. Greedy Algorithms
Algorithm Design Methods
Merge Sort 7/29/ :21 PM The Greedy Method The Greedy Method.
The Greedy Method and Text Compression
Greedy Algorithms (Chap. 16)
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Presented by Po-Chuan & Chen-Chen 2016/03/08
Three Graph Algorithms
Greedy Method     Greedy Matching     Coin Changing     Minimum Spanning Tree     Fractional Knapsack     Dijkstra's Single-Source Shortest-Path.
CSCE350 Algorithms and Data Structure
Minimum Spanning Tree.
ICS 353: Design and Analysis of Algorithms
Merge Sort 11/28/2018 2:18 AM The Greedy Method The Greedy Method.
Merge Sort 11/28/2018 2:21 AM The Greedy Method The Greedy Method.
Merge Sort 11/28/2018 8:16 AM The Greedy Method The Greedy Method.
Greedy Algorithms Many optimization problems can be solved more quickly using a greedy approach The basic principle is that local optimal decisions may.
Chapter 16: Greedy algorithms Ming-Te Chi
Merge Sort 1/17/2019 3:11 AM The Greedy Method The Greedy Method.
Graph Searching.
Richard Anderson Lecture 6 Greedy Algorithms
Greedy Algorithms TOPICS Greedy Strategy Activity Selection
Chapter 16: Greedy algorithms Ming-Te Chi
Richard Anderson Autumn 2016 Lecture 7
Richard Anderson Lecture 7 Greedy Algorithms
Algorithm Design Methods
Greedy Algorithms Comp 122, Spring 2004.
Algorithm Design Techniques Greedy Approach vs Dynamic Programming
Algorithm Design Methods
What is Computer Science About? Part 2: Algorithms
Richard Anderson Winter 2019 Lecture 7
Merge Sort 5/2/2019 7:53 PM The Greedy Method The Greedy Method.
Winter 2019 Lecture 11 Minimum Spanning Trees (Part II)
Richard Anderson Autumn 2015 Lecture 7
Lecture 14 Minimum Spanning Tree (cont’d)
Advance Algorithm Dynamic Programming
Algorithm Design Methods
Autumn 2019 Lecture 11 Minimum Spanning Trees (Part II)
Presentation transcript:

Design & Analysis of Algorithm Greedy Algorithm Informatics Department Parahyangan Catholic University

Greedy Algorithm Greedy algorithm builds up a solution piece by piece, always choosing the next piece that offers the most obvious and immediate benefit Example : Chess VS Scrabble

Example : Prim’s MST Build a minimum spanning tree from a graph of n vertices Start with an tree T with one vertex “root” Performs n-1 iterations, each adding one vertex to T with the smallest edge weight

Example : Kruskal’s MST Build a minimum spanning tree from a graph of n vertices Start with an empty tree T Performs n-1 iterations, each adding the smallest weighted edge to T that doesn’t produce a cycle

Example : Huffman’s Algorithm Build a Huffman tree out of n elements Performs n-1 iterations, each merging two elements with smallest frequency

0/1 Knapsack Problem Given a set S of n items, each having size and value, and a knapsack of size C Find a subset of S which maximize the value and total size must not exceed C Can we solve 0/1 Knapsack problem with greedy approach ?

Fractional Knapsack Problem Given a set S of n items, each having size and value, and a knapsack of size C Find a subset of S which maximize the value and total size must not exceed C We are allowed to take fractions of the items Can we solve this problem using greedy approach ? Why is it correct ?

Making Change 25 ¢ 10 ¢ 5 ¢ 1 ¢ How to make a change of n ¢ using as few coins as possible ? Does this work if denominations of coins are 1 ¢, 10 ¢, 12 ¢ ? Try making 30 ¢ change !

Greedy Algorithm Advantages Disadvantages Work fast when they work Simple and easy to implement Disadvantages Does not always produce an optimal solution to every problem Correctness of greedy algorithm is hard to prove

Exercise : Gas Station A traveler needs to drive along a highway to reach the next town he wants to visit. His car can go up to 200 km on full tank. There are gas stations at d1, d2, ..., dn. Starting with full tank, give a greedy algorithm that minimize the number of stops for buying gas.

Activities Scheduling Given a set S = {a1, a2, . . . , an} of n proposed activities that wish to use a lecture hall, which can be used by only one activity at a time Each activity ai has a start time si and a finish time fi Give a greedy algorithm that maximize the number of activities scheduled

Activities Scheduling Choose the shortest time first ? Sort by start time ? Sort by end time ? a1 a2 a3 a1 a2 a3 a4 a5 Works ! But why ?

Correctness It is easy to show that an algorithm is incorrect  give a counter example However, it is harder to show that an algorithm is correct  need formal proof

Exercise : Volunteers Scheduling Jaan is scheduling volunteers to work at an information booth. Each volunteer sends Jaan a time interval that he or she is willing to work. The interval is specified by a starting time and a finishing time. For example, one volunteer might say that he is willing to work at the information booth from 10:13 a.m. until 11:42 a.m. Then Jaan must choose a set of volunteers so that there is at least one person at the information booth at all times between 8:00 a.m. and 10:00 p.m. Jaan wants to use the smallest possible number of volunteers to achieve this.

Exercise : Volunteers Scheduling (a) One possible greedy algorithm for this problem would be to sort the volunteers so that the lengths of their intervals are in non-increasing order, and then go through them one-by- one, scheduling anyone who is willing to work at some time that is not already covered by other scheduled volunteers. Show that this strategy does not always yield an optimal solution. (b) Design a simple and efficient greedy algorithm that does always yield an optimal solution.