A greedy algorithm is an algorithm that follows the problem solving heuristic of making the locally optimal choice at each stage with the hope of finding.

Slides:



Advertisements
Similar presentations
Dynamic Programming 25-Mar-17.
Advertisements

CS 332: Algorithms NP Completeness David Luebke /2/2017.
Introduction to Algorithms 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.
Types of Algorithms.
Chapter 5 Fundamental Algorithm Design Techniques.
Analysis of Algorithms
Greed is good. (Some of the time)
Dynamic Programming.
15-May-15 Dynamic Programming. 2 Algorithm types Algorithm types we will consider include: Simple recursive algorithms Backtracking algorithms Divide.
Lecture 7: Greedy Algorithms II Shang-Hua Teng. Greedy algorithms A greedy algorithm always makes the choice that looks best at the moment –My everyday.
1 Greedy Algorithms. 2 2 A short list of categories Algorithm types we will consider include: Simple recursive algorithms Backtracking algorithms Divide.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 1 (Part 3) Tuesday, 9/4/01 Greedy Algorithms.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2006 Lecture 2 Monday, 9/13/06 Design Patterns for Optimization Problems.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2002 Monday, 12/2/02 Design Patterns for Optimization Problems Greedy.
CSE 780 Algorithms Advanced Algorithms Greedy algorithm Job-select problem Greedy vs DP.
CS3381 Des & Anal of Alg ( SemA) City Univ of HK / Dept of CS / Helena Wong 5. Greedy Algorithms - 1 Greedy.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2002 Lecture 1 (Part 3) Tuesday, 1/29/02 Design Patterns for Optimization.
ASC Program Example Part 3 of Associative Computing Examining the MST code in ASC Primer.
Week 2: Greedy Algorithms
Lecture 7: Greedy Algorithms II
Clustering and greedy algorithms Prof. Noah Snavely CS1114
1 Algorithm Design Techniques Greedy algorithms Divide and conquer Dynamic programming Randomized algorithms Backtracking.
10/31/02CSE Greedy Algorithms CSE Algorithms Greedy Algorithms.
10/31/02CSE Greedy Algorithms CSE Algorithms Greedy Algorithms.
David Luebke 1 8/23/2015 CS 332: Algorithms Greedy Algorithms.
Lecture 23. Greedy Algorithms
Fundamentals of Algorithms MCS - 2 Lecture # 7
Dr. Naveed Ahmad Assistant Professor Department of Computer Science University of Peshawar.
 Greedy Algorithms. Greedy Algorithm  Greedy Algorithm - Makes locally optimal choice at each stage. - For optimization problems.  If the local optimum.
David Luebke 1 10/24/2015 CS 332: Algorithms Greedy Algorithms Continued.
CSC 413/513: Intro to Algorithms Greedy Algorithms.
Image segmentation Prof. Noah Snavely CS1114
Introduction to Algorithms Chapter 16: Greedy Algorithms.
Greedy Methods and Backtracking Dr. Marina Gavrilova Computer Science University of Calgary Canada.
Honors Track: Competitive Programming & Problem Solving Optimization Problems Kevin Verbeek.
CSC 201: Design and Analysis of Algorithms Greedy Algorithms.
Greedy Algorithms. What is “Greedy Algorithm” Optimization problem usually goes through a sequence of steps A greedy algorithm makes the choice looks.
Backtracking Opening Discussion zWhat did we talk about last class? zDo you have any questions about the assignments?
December 14, 2015 Design and Analysis of Computer Algorithm Pradondet Nilagupta Department of Computer Engineering.
Types of Algorithms. 2 Algorithm classification Algorithms that use a similar problem-solving approach can be grouped together We’ll talk about a classification.
1 Algorithms CSCI 235, Fall 2015 Lecture 30 More Greedy Algorithms.
Greedy Algorithms BIL741: Advanced Analysis of Algorithms I (İleri Algoritma Çözümleme I)1.
Greedy algorithms David Kauchak cs302 Spring 2012.
Greedy Algorithms Chapter 16 Highlights
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.
Maximum Flow and Dynamic Programming Opening Discussion zWho can describe a flow network to me. What are the properties it has and what types.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 18.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 17.
Greedy Algorithms.
CSC317 Greedy algorithms; Two main properties:
Algorithm Design Methods
Types of Algorithms.
Multi - Way Number Partitioning
Algorithm Design Methods
Types of Algorithms.
CS4335 Design and Analysis of Algorithms/WANG Lusheng
Advanced Analysis of Algorithms
Advanced Algorithms Analysis and Design
Graph Searching.
CSC 380: Design and Analysis of Algorithms
Types of Algorithms.
Algorithm Design Methods
The results for Challenging Problem 1.
Major Design Strategies
Algorithms CSCI 235, Spring 2019 Lecture 30 More Greedy Algorithms
Advance Algorithm Dynamic Programming
Major Design Strategies
Algorithm Design Methods
Presentation transcript:

A greedy algorithm is an algorithm that follows the problem solving heuristic of making the locally optimal choice at each stage with the hope of finding a global optimum.

 An optimization problem is one in which you want to find, not just a solution but best solution  Search technique look at many possible solutions eg dynamic programming or backtrack search  A “greedy algorithm” sometimes works well for optimization problems

A greedy algorithm works in a phases At each phase:  You take the best you can get right now without regard for future  You hope that by choosing a local optimum at each step, you will end up at a global optimum  For some problems, greedy approch always gets optimum

 For others, greedy finds good, but not always best. If so it is called greedy heuristic, or opproximation  For still other greedy approch can do very poorly

 Construct optimum solution piece by piece  Generic Step Having constructed some part of optimum solution extend this by identifing the next part

Comparison: Dynamic ProgrammingGreedy Algorithms At each step, the choice is determined based on solutions of subproblems. At each step, we quickly make a choice that currently looks best. --A local optimal (greedy) choice. Bottom-up approachTop-down approach Sub-problems are solved first.Greedy choice can be made first before solving further sub-problems. Can be slower, more complexUsually faster, simpler

A thief robbing a store finds n items. i th item: worth v i dollars w i pounds W, w i, v i are integers. He can carry at most W pounds. 0-1 Knapsack Problem: Which items should I take?

A thief robbing a store finds n items. i th item: worth v i dollars w i pounds W, w i, v i are integers. He can carry at most W pounds. He can take fractions of items. Fractional Knapsack Problem: ?

Both problems are similar. But Fractional Knapsack Problem can be solved in a greedy strategy. Step 1.Compute the value per pound for each item E.g. gold dust: $10000 per pound (most expensive) Silver dust: $2000 per pound Copper dust: $500 per pound Step 2.Take as much as possible of the most expensive (ie. Gold dust) Step 3. If the supply of that item is exhausted (ie. no more gold) and he can still carry more, he takes as much as possible of the item that is next most expensive and so forth until he can’t carry any more.

We can solve the Fractional Knapsack Problem by a greedy algorithm: Always makes the choice that looks best at the moment. i.e., A locally optimal Choice

 You have to run nine jobs, with running times of 3, 5, 6, 10, 11, 14, 15, 18, and 20 minutes  You have three processors on which you can run these jobs  You decide to do the longest-running jobs first, on whatever processor is available  Time to completion: = 35 minutes  This solution isn’t bad, but we might be able to do better P1 P2 P3

 What would be the result if you ran the shortest job first?  Again, the running times are 3, 5, 6, 10, 11, 14, 15, 18, and 20 minutes  That wasn’t such a good idea; time to completion is now = 40 minutes  Note, however, that the greedy algorithm itself is fast  All we had to do at each stage was pick the minimum or maximum P1 P2 P3

 Better solutions do exist:  This solution is clearly optimal (why?)  Clearly, there are other optimal solutions (why?)  How do we find such a solution?  One way: Try all possible assignments of jobs to processors  Unfortunately, this approach can take exponential time P1 P2 P3