Greedy Algorithms Reading Material: –Alsuwaiyel’s Book: Section 8.1 –CLR Book (2 nd Edition): Section 16.1.

Slides:



Advertisements
Similar presentations
Lecture 7 Paradigm #5 Greedy Algorithms
Advertisements

CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Comp 122, Spring 2004 Greedy Algorithms. greedy - 2 Lin / Devi Comp 122, Fall 2003 Overview  Like dynamic programming, used to solve optimization problems.
1.1 Data Structure and Algorithm Lecture 6 Greedy Algorithm Topics Reference: Introduction to Algorithm by Cormen Chapter 17: Greedy Algorithm.
Greedy Algorithms Greed is good. (Some of the time)
Analysis of Algorithms
Greedy Algorithms Be greedy! always make the choice that looks best at the moment. Local optimization. Not always yielding a globally optimal solution.
Introduction to Algorithms Jiafen Liu Sept
Greedy Algorithms Basic idea Connection to dynamic programming
Greedy Algorithms Basic idea Connection to dynamic programming Proof Techniques.
Cs333/cutler Greedy1 Introduction to Greedy Algorithms The greedy technique Problems explored –The coin changing problem –Activity selection.
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.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2006 Lecture 2 Monday, 2/6/06 Design Patterns for Optimization.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2006 Lecture 2 Monday, 9/13/06 Design Patterns for Optimization Problems.
Greedy Algorithms CIS 606 Spring Greedy Algorithms Similar to dynamic programming. Used for optimization problems. Idea – When we have a choice.
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 Fall, 2006 Design Patterns for Optimization Problems Dynamic Programming.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2008 Design Patterns for Optimization Problems Dynamic Programming.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2008 Lecture 2 Tuesday, 9/16/08 Design Patterns for Optimization.
Week 2: Greedy Algorithms
Lecture 7: Greedy Algorithms II
1 The Greedy Method CSC401 – Analysis of Algorithms Lecture Notes 10 The Greedy Method Objectives Introduce the Greedy Method Use the greedy method to.
16.Greedy algorithms Hsu, Lih-Hsing. Computer Theory Lab. Chapter 16P An activity-selection problem Suppose we have a set S = {a 1, a 2,..., a.
David Luebke 1 8/23/2015 CS 332: Algorithms Greedy Algorithms.
Greedy Algorithms Dr. Yingwu Zhu. Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that.
Data Structures and Algorithms A. G. Malamos
David Luebke 1 10/24/2015 CS 332: Algorithms Greedy Algorithms Continued.
CSC 413/513: Intro to Algorithms Greedy Algorithms.
The Greedy Method. The Greedy Method Technique The greedy method is a general algorithm design paradigm, built on the following elements: configurations:
CSC 201: Design and Analysis of Algorithms Greedy Algorithms.
COSC 3101A - Design and Analysis of Algorithms 8 Elements of DP Memoization Longest Common Subsequence Greedy Algorithms Many of these slides are taken.
Greedy Algorithms. What is “Greedy Algorithm” Optimization problem usually goes through a sequence of steps A greedy algorithm makes the choice looks.
December 14, 2015 Design and Analysis of Computer Algorithm Pradondet Nilagupta Department of Computer Engineering.
CSC5101 Advanced Algorithms Analysis
Greedy Algorithms BIL741: Advanced Analysis of Algorithms I (İleri Algoritma Çözümleme I)1.
CS 3343: Analysis of Algorithms Lecture 19: Introduction to Greedy Algorithms.
Greedy Algorithms Chapter 16 Highlights
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2010 Lecture 2 Tuesday, 2/2/10 Design Patterns for Optimization.
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.
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Prof. Sumanta Guha Slide Sources: CLRS “Intro.
1 Algorithms CSCI 235, Fall 2015 Lecture 29 Greedy Algorithms.
Greedy Algorithms Lecture 10 Asst. Prof. Dr. İlker Kocabaş 1.
Divide and Conquer. Problem Solution 4 Example.
6/13/20161 Greedy A Comparison. 6/13/20162 Greedy Solves an optimization problem: the solution is “best” in some sense. Greedy Strategy: –At each decision.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 17.
CS6045: Advanced Algorithms Greedy Algorithms. Main Concept –Divide the problem into multiple steps (sub-problems) –For each step take the best choice.
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 General principle of greedy algorithm
Greedy algorithms: CSC317
Analysis of Algorithms CS 477/677
Greedy Algorithms (Chap. 16)
Greedy Algorithms / Interval Scheduling Yin Tat Lee
Presented by Po-Chuan & Chen-Chen 2016/03/08
ICS 353: Design and Analysis of Algorithms
CS 3343: Analysis of Algorithms
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
Advanced Algorithms Analysis and Design
Advanced Algorithms Analysis and Design
Richard Anderson Lecture 6 Greedy Algorithms
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Chapter 16: Greedy algorithms Ming-Te Chi
Richard Anderson Lecture 7 Greedy Algorithms
ICS 353: Design and Analysis of Algorithms
Algorithms CSCI 235, Spring 2019 Lecture 29 Greedy Algorithms
Greedy Algorithms Comp 122, Spring 2004.
Algorithm Design Techniques Greedy Approach vs Dynamic Programming
Asst. Prof. Dr. İlker Kocabaş
Advance Algorithm Dynamic Programming
Presentation transcript:

Greedy Algorithms Reading Material: –Alsuwaiyel’s Book: Section 8.1 –CLR Book (2 nd Edition): Section 16.1

Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming algorithms, –greedy algorithms are iterative in nature. –An optimal solution is reached from local optimal solutions. –This approach does not work all the time. –A proof that the algorithm does what it claims is needed, and usually not easy to get.

Fractional Knapsack Problem Given n items of sizes s 1, s 2, …, s n and values v 1, v 2, …, v n and size C, the problem is to find x 1, x 2, …, x n  that maximize subject to

Solution to Fractional Knapsack Problem Consider y i = v i / s i What is y i ? What is the solution?

Activity Selection Problem Problem Formulation –Given a set of n activities, S = {a 1, a 2,..., a n } that require exclusive use of a common resource, find the largest possible set of nonoverlapping activities (also called mutually compatible). For example, scheduling the use of a classroom. –Assume that a i needs the resource during period [s i, f i ), which is a half-open interval, where s i = start time of the activity, and f i = finish time of the activity. Note: Could have many other objectives: –Schedule room for longest time. –Maximize income rental fees.

Activity Selection Problem: Example Assume the following set S of activities that are sorted by their finish time, find a maximum-size mutually compatible set. i sisi fifi

i sisi fifi

Solving the Activity Selection Problem Define S i,j = {a k  S : f i  s k < f k  s j } –activities that start after a i finishes and finish before a j starts Activities in S i,j are compatible with: – Add the following [fictitious] activities a 0 = [– , 0) and a n+1 = [ ,  +1) Hence, S = S 0,n+1 and the range of S i,j is 0  i,j  n+1

Solving the Activity Selection Problem Assume that activities are sorted by monotonically increasing finish time: –i.e., f 0  f 1  f 2 ...  f n < f n+1 Then, S i,j =  for i  j. Proof: Therefore, we only need to worry about S i,j where 0  i < j  n+1

Solving the Activity Selection Problem Suppose that a solution to S i,j includes a k. We have 2 sub-problems: –S i,k (start after a i finishes, finish before a k starts) –S k,j (start after a k finishes, finish before a j starts) The Solution to S i,j is (solution to S i,k )  {a k }  (solution to S k,j ) Since a k is in neither sub-problem, and the subproblems are disjoint, |solution to S| = |solution to S i,k |+1+|solution to S k,j |

Recursive Solution to Activity Selection Problem Let A i,j = optimal solution to S i,j. So A i,j = A i,k  {a k }  A k,j, assuming: –S i,j is nonempty, and –we know a k. Hence,

Finding the Greedy Algorithm Theorem: Let S i,j  , and let a m be the activity in S i,j with the earliest finish time: f m = min { f k : a k  S i,j }. Then: 1.a m is used in some maximum-size subset of mutually compatible activities of S i,j 2.S im = , so that choosing a m leaves S m,j as the only nonempty subproblem.

Recursive Greedy Algorithm

Iterative Greedy Algorithm

Greedy Strategy 1.Determine the optimal substructure. 2.Develop a recursive solution. 3.Prove that at any stage of recursion, one of the optimal choices is the greedy choice. Therefore, it's always safe to make the greedy choice. 4.Show that all but one of the subproblems resulting from the greedy choice are empty. 5.Develop a recursive greedy algorithm. 6.Convert it to an iterative algorithm.

Money Change Problem Given a currency system that has n coins with values v 1, v 2,..., v n, where v 1 = 1, the objective is to pay change of value y in such a way that the total number of coins is minimized. More formally, we want to minimize the quantity subject to the constraint Here, x 1, x 2,..., x n, are nonnegative integers (so x i may be zero).

Money Change Problem What is a greedy algorithm to solve this problem? Is the greedy algorithm optimal?