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.
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
Greedy Algorithms Basic idea Connection to dynamic programming Proof Techniques.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 7: Greedy Algorithms
Greedy Algorithms Reading Material: –Alsuwaiyel’s Book: Section 8.1 –CLR Book (2 nd Edition): Section 16.1.
CSE 421 Algorithms Richard Anderson Lecture 6 Greedy Algorithms.
10/31/02CSE Greedy Algorithms CSE Algorithms 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.
10/31/02CSE Greedy Algorithms CSE Algorithms 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.
Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math.
1 Algorithms & Data Structures for Games Lecture 2A Minor Games Programming.
December 14, 2015 Design and Analysis of Computer Algorithm Pradondet Nilagupta Department of Computer Engineering.
1 Chapter 5-1 Greedy Algorithms Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
SPANNING TREES Lecture 21 CS2110 – Fall Nate Foster is out of town. NO 3-4pm office hours today!
1 Chapter 16: Greedy Algorithm. 2 About this lecture Introduce Greedy Algorithm Look at some problems solvable by Greedy Algorithm.
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.
Greedy Algorithms Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Greedy Algorithms Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Greedy Algorithms.
Greedy Algorithms – Chapter 5
Lecture on Design and Analysis of Computer Algorithm
CS 3343: Analysis of Algorithms
Merge Sort 7/29/ :21 PM The Greedy Method The Greedy Method.
Design & Analysis of Algorithm Greedy Algorithm
Greedy Algorithms Basic idea Connection to dynamic programming
Greedy Algorithms / Interval Scheduling Yin Tat Lee
Greedy Algorithms.
Greedy Method     Greedy Matching     Coin Changing     Minimum Spanning Tree     Fractional Knapsack     Dijkstra's Single-Source Shortest-Path.
Critical Path Analysis
Richard Anderson Autumn 2015 Lecture 8 – Greedy Algorithms II
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.
Graph Searching.
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
CSCE 222 Discrete Structures for Computing
Richard Anderson Winter 2019 Lecture 8 – Greedy Algorithms II
Richard Anderson Autumn 2016 Lecture 8 – Greedy Algorithms II
Richard Anderson Winter 2019 Lecture 7
Merge Sort 5/2/2019 7:53 PM The Greedy Method The Greedy Method.
Week 2: Greedy Algorithms
Spanning Trees Lecture 20 CS2110 – Spring 2015.
Greedy algorithms.
Richard Anderson Autumn 2015 Lecture 7
Asst. Prof. Dr. İlker Kocabaş
Richard Anderson Autumn 2019 Lecture 7
Richard Anderson Autumn 2019 Lecture 8 – Greedy Algorithms II
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 Can extend this to figuring out how many rooms are needed to schedule events.

Example (last programming lab): Dragon of Loowater N heads of dragons, M knights Each dragon head and each knight has a value, only knights with greater value than the head can defeat it Knights can defeat one head only Match knights with dragon heads to minimize total knight height Greedy solution: Choose the shortest knight needed Sort the heads and the knights For smallest head, pick smallest knight possible, then repeat until done

More Greedy solutions Will see several examples later on – e.g. in some graph applications Balancing Stations (see book) Grouping most w/least Watering Grass (see book) Minimizing Lateness Optimal Caching