Greedy Algorithms.

Slides:



Advertisements
Similar presentations
COMP 482: Design and Analysis of Algorithms
Advertisements

COMP 482: Design and Analysis of Algorithms
1 Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Greedy Algorithms.
The Greedy Method1. 2 Outline and Reading The Greedy Method Technique (§5.1) Fractional Knapsack Problem (§5.1.1) Task Scheduling (§5.1.2) Minimum Spanning.
1.1 Data Structure and Algorithm Lecture 6 Greedy Algorithm Topics Reference: Introduction to Algorithm by Cormen Chapter 17: Greedy Algorithm.
Instructor Neelima Gupta Table of Contents Greedy Algorithms.
Greedy Algorithms Be greedy! always make the choice that looks best at the moment. Local optimization. Not always yielding a globally optimal solution.
Greedy Algorithms Basic idea Connection to dynamic programming
Five Problems CSE 421 Richard Anderson Winter 2009, Lecture 3.
Greedy Algorithms Basic idea Connection to dynamic programming Proof Techniques.
CSE 421 Algorithms Richard Anderson Lecture 6 Greedy Algorithms.
9/3/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Guest lecturer: Martin Furer Algorithm Design and Analysis L ECTURE.
Called as the Interval Scheduling Problem. A simpler version of a class of scheduling problems. – Can add weights. – Can add multiple resources – Can ask.
9/8/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 6 Greedy Algorithms.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 8.
Greedy Algorithms. Surprisingly, many important and practical computational problems can be solved this way. Every two year old knows the greedy algorithm.
CSCI 256 Data Structures and Algorithm Analysis Lecture 6 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
The Greedy Method. The Greedy Method Technique The greedy method is a general algorithm design paradigm, built on the following elements: configurations:
Greedy Algorithms. What is “Greedy Algorithm” Optimization problem usually goes through a sequence of steps A greedy algorithm makes the choice looks.
1 Chapter 5-1 Greedy Algorithms Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
CSEP 521 Applied Algorithms Richard Anderson Winter 2013 Lecture 3.
CS 361 – Chapter 10 “Greedy algorithms” It’s a strategy of solving some problems –Need to make a series of choices –Each choice is made to maximize current.
CSE 421 Algorithms Richard Anderson Lecture 8 Greedy Algorithms: Homework Scheduling and Optimal Caching.
1 Algorithms CSCI 235, Fall 2015 Lecture 29 Greedy Algorithms.
Greedy Algorithms Lecture 10 Asst. Prof. Dr. İlker Kocabaş 1.
Lecture 9 CSE 331 June 18, The “real” end of Semester blues MondayTuesdayWednesdayThursdayFriday Project 331 HW Exam study Party! Write up a term.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 17.
Greedy Algorithms.
Data Structures Lab Algorithm Animation.
Greedy Algorithms – Chapter 5
Problem solving sequence
CHAPTER 8 Operations Scheduling
CS 3343: Analysis of Algorithms
Merge Sort 7/29/ :21 PM The Greedy Method The Greedy Method.
Analysis of Algorithms CS 477/677
Greedy Algorithms Basic idea Connection to dynamic programming
Chapter 4 Greedy Algorithms
Greedy Algorithms / Interval Scheduling Yin Tat Lee
Presented by Po-Chuan & Chen-Chen 2016/03/08
Lecture 21 CSE 331 Oct 21, 2016.
Richard Anderson Autumn 2015 Lecture 8 – Greedy Algorithms II
Lecture 21 CSE 331 Oct 20, 2017.
Merge Sort 11/28/2018 2:18 AM The Greedy Method The Greedy Method.
Merge Sort 11/28/2018 8:16 AM The Greedy Method The Greedy Method.
Greedy Algorithm Enyue (Annie) Lu.
Discrete Mathematics CMP-101 Lecture 12 Sorting, Bubble Sort, Insertion Sort, Greedy Algorithms Abdul Hameed
Advanced Algorithms Analysis and Design
Greedy Algorithms.
Greedy Algorithms: Homework Scheduling and Optimal Caching
Merge Sort 1/17/2019 3:11 AM The Greedy Method The Greedy Method.
Lecture 6 Topics Greedy Algorithm
Richard Anderson Lecture 6 Greedy Algorithms
Greedy Algorithms Alexandra Stefan.
Richard Anderson Autumn 2016 Lecture 7
Richard Anderson Lecture 7 Greedy Algorithms
Algorithms CSCI 235, Spring 2019 Lecture 29 Greedy Algorithms
Richard Anderson Winter 2019 Lecture 8 – Greedy Algorithms II
Richard Anderson Autumn 2016 Lecture 8 – Greedy Algorithms II
Richard Anderson Winter 2019 Lecture 7
CSE 421, University of Washington, Autumn 2006
Merge Sort 5/2/2019 7:53 PM The Greedy Method The Greedy Method.
Algorithms CSCI 235, Spring 2019 Lecture 35 Graphs IV
Week 2: Greedy Algorithms
Greedy algorithms.
Richard Anderson Autumn 2015 Lecture 7
Analysis of Algorithms CS 477/677
Richard Anderson Autumn 2019 Lecture 7
Richard Anderson Autumn 2019 Lecture 8 – Greedy Algorithms II
CSE 421 Richard Anderson Autumn 2019, Lecture 3
Presentation transcript:

Greedy Algorithms

The two key components Optimal Sub-structure Greedy Property You solve the problem by solving a sub-problem optimally Greedy Property Using the choice that seems best at the moment leads to the optimal result This is tougher to show! Greedy problems are the “easy” ones for finding optimal results They are less common than the “tough” ones, unfortunately…

Classical problem: Making change Given Coins: 1 cent, 5, 10, 25, 50, and 100 cents, how can you get a certain total in the fewest coins? Straightforward: choose most of the largest coin, then next largest, etc. For these denominations, this is optimal, but this is NOT true for general coin values. Example: 1, 10, 15, 20 cent denominations 25 cent goal Greedy strategy would give 20+1+1+1+1+1 Optimal result would be 10+15 The point: you need to ensure that you have a situation where greedy applies!

Classical problem: Scheduling jobs Every job has a start and a finish time Can work on only one job at a time Want to schedule as many jobs as possible

Possible greedy choices Take jobs in order of earliest start time Take jobs in order of earliest finish time Take jobs in order of length of job (shortest job first) Take jobs in order of fewest conflicts with other jobs

Earliest Start Shortest Job Fewest Conflicts

Possible greedy choices Take jobs in order of earliest start time Take jobs in order of earliest finish time Take jobs in order of length of job (shortest job first) Take jobs in order of fewest conflicts with other jobs Only the earliest finish time leads to an optimal solution! If there were any other optimal solution not including that, you could replace one of those choices with the one that ends earlier, and still have an optimal solution. Need to think about what would happen if there WERE a better solution from the non-greedy choice – show there’s a conflict or that the greedy choice is just as good

Room Scheduling Assume classes with start and end times (like tasks, above) How many rooms are needed to teach all of them? Same as the depth – the number of tasks overlapping at once Can use a greedy approach: Just assign to first available room. Sort start and end times together. Then linearly process Each time a start is passed, increase by 1, each time an end is passed, decrease by 1 Keep track of how many rooms max were needed This is also the basis for the sweep-and-prune approach for collision detection in graphics!

Minimizing maximum lateness Tasks of particular length, and deadline time. Want to minimize the maximum lateness Can always do task with earliest deadline first Ensures that there is no “idle” time – the best solution must also have no idle time. Reversing any two from that order will lead to a worse result So, that order can’t change.

More Greedy solutions Will see several examples later on – e.g. in some graph applications Balancing Stations (see book) Grouping most w/least See book for some more specific examples