Lecture 6 Topics Greedy Algorithm

Slides:



Advertisements
Similar presentations
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Advertisements

Greedy Algorithms.
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.
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 Fall, 2001 Lecture 1 (Part 3) Tuesday, 9/4/01 Greedy Algorithms.
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.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2002 Monday, 12/2/02 Design Patterns for Optimization Problems Greedy.
Greedy Algorithms CIS 606 Spring Greedy Algorithms Similar to dynamic programming. Used for optimization problems. Idea – When we have a choice.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Spring, 2002 Lecture 1 (Part 3) Tuesday, 1/29/02 Design Patterns for Optimization.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2008 Lecture 2 Tuesday, 9/16/08 Design Patterns for Optimization.
Lecture 7: Greedy Algorithms II
CSCI 256 Data Structures and Algorithm Analysis Lecture 6 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
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.
December 14, 2015 Design and Analysis of Computer Algorithm Pradondet Nilagupta Department of Computer Engineering.
Algorithm Design Methods 황승원 Fall 2011 CSE, POSTECH.
Greedy Algorithms BIL741: Advanced Analysis of Algorithms I (İleri Algoritma Çözümleme I)1.
1 Algorithms CSCI 235, Fall 2015 Lecture 29 Greedy Algorithms.
Greedy Algorithms Lecture 10 Asst. Prof. Dr. İlker Kocabaş 1.
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.
PREPARED BY: Qurat Ul Ain SUBMITTED TO: Ma’am Samreen.
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.
CSCI 58000, Algorithm Design, Analysis & Implementation Lecture 12 Greedy Algorithms (Chapter 16)
Greedy Algorithms General principle of greedy algorithm
Dynamic Programming Sequence of decisions. Problem state.
Lecture on Design and Analysis of Computer Algorithm
Greedy Method 6/22/2018 6:57 PM Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015.
Algorithm Design Methods
Merge Sort 7/29/ :21 PM The Greedy Method The Greedy Method.
The Greedy Method and Text Compression
Analysis of Algorithms CS 477/677
Greedy Algorithms (Chap. 16)
Introduction to Algorithms`
Greedy Algorithm.
Greedy Algorithms Basic idea Connection to dynamic programming
Presented by Po-Chuan & Chen-Chen 2016/03/08
Algorithm Design Methods
Prepared by Chen & Po-Chuan 2016/03/29
ICS 353: Design and Analysis of Algorithms
CS 3343: Analysis of Algorithms
Merge Sort 11/28/2018 2:18 AM The Greedy Method The Greedy Method.
The Greedy Method Spring 2007 The Greedy Method Merge Sort
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 Algorithm Enyue (Annie) Lu.
Chapter 16: Greedy algorithms Ming-Te Chi
Advanced Algorithms Analysis and Design
Greedy Algorithms.
Advanced Algorithms Analysis and Design
Merge Sort 1/17/2019 3:11 AM The Greedy Method The Greedy Method.
Greedy Algorithms TOPICS Greedy Strategy Activity Selection
Chapter 16: Greedy algorithms Ming-Te Chi
Algorithms CSCI 235, Spring 2019 Lecture 29 Greedy Algorithms
Algorithm Design Methods
Greedy Algorithms Comp 122, Spring 2004.
Algorithm Design Techniques Greedy Approach vs Dynamic Programming
Lecture 6 Greedy Algorithms
Algorithm Design Methods
Merge Sort 5/2/2019 7:53 PM The Greedy Method The Greedy Method.
Greedy algorithms.
Asst. Prof. Dr. İlker Kocabaş
Advance Algorithm Dynamic Programming
Algorithm Design Methods
Presentation transcript:

Lecture 6 Topics Greedy Algorithm Reference: Introduction to Algorithm by Cormen Chapter 17: Greedy Algorithm Data Structure and Algorithm

Greedy Algorithm Algorithm for optimization problems typically go through a sequence of steps, with a set of choices at each step. For many optimization problems, greedy algorithm can be used. (not always) Greedy algorithm always makes the choice that looks best at the moment. It makes a locally optimal choice in the hope that this choice will lead to a globally optimal solution. Example: Activity Selection Problem Dijkstra’s Shortest Path Problem Minimum Spanning Tree Problem Data Structure and Algorithm

Activity Selection Problem Definition: Scheduling a resource among several competing activities. Elaboration: Suppose we have a set S = {1,2,…,n} of n proposed activities that wish to use a resource, such as a lecture hall, which can be used by only one activity at a time. Each activity i has a start time si and finish time fi where si<= fi. Compatibility: Activities i and j are compatible if the interval [si, fi) and [sj, fj) do not overlap (i.e. si>= fj or sj>= fi ) Goal: To select a maximum- size set of mutually compatible activities. Data Structure and Algorithm

Activity Selection Problem (Cont.) Assume that Input activities are sorted by increasing finishing time. [ complexity O(nlg2n) ] [ s and f are starting and finishing time array respectively] Activity_Selector (s, f) Complexity=O(n) n = length(s) A = {1} j = 1 for i = 2 to n do if si >= fj then A = A U {i} j = i return A Data Structure and Algorithm

Activity Selection Problem (Cont.) The next selected activity is always the one with the earliest finish time that can be legally scheduled. The activity picked is thus a greedy choice in the sense that it leaves as much opportunity as possible for the remaining activities to be scheduled. That is, the greedy choice is the one that maximizes the amount of unscheduled time remaining. Data Structure and Algorithm

Elements of the Greedy Strategy A greedy algorithm obtains an optimal solution by making a sequence of choices. The choice that seems best at the moment is chosen. This strategy does not always produces an optimal solution. Then how can one tell if a greedy algorithm will solve a particular optimization problem?? Data Structure and Algorithm

Elements of the Greedy Strategy (Cont.) How can one tell if a greedy algorithm will solve a particular optimization problem?? There is no way in general. But there are 2 ingredients exhibited by most greedy problems: Greedy Choice Property Optimal Sub Structure Data Structure and Algorithm

Greedy Choice Property A globally optimal solution can be arrived at by making a locally optimal (Greedy) choice. We make whatever choice seems best at the moment and then solve the sub problems arising after the choice is made. The choice made by a greedy algorithm may depend on choices so far, by it cannot depend on any future choices or on the solutions to sub problems. Thus, a greedy strategy usually progresses in a top-down fashion, making one greedy choice after another, iteratively reducing each given problem instance to a smaller one. Data Structure and Algorithm

Optimal Sub Structure A problem exhibits optimal substructure if an optimal solution to the problem contains (within it) optimal solution to sub problems. In Activity Selection Problem, an optimal solution A begins with activity 1, then the set of activities Ā = A – {1} is an optimal solution to the activity selection problem Ś = {i € S: si>= f1} Data Structure and Algorithm

Knapsack Problem (Fractional) We are given n objects and a knapsack. Object i has a weight wi and the knapsack has a capacity M. If a fraction xi, [0<= xi <=1] of object i is placed into the knapsack then a profit of pixi is earned. The objective is to obtain a filling of the knapsack that maximize the total profit earned. Maximize ∑ pixi [1<= i <= n ] subject to ∑ wixi <= M [1<= i <= n ] Data Structure and Algorithm

Knapsack Problem (Fractional) [ P = profit array of the objects, W = weight array of the objects, X = Object Array, n=number of objects, M= knapsack capacity ] [objects are ordered so that P(i)/W(i) >= P(i+1)/W(i+1)] Knapsack(M, n) [ Complexity= O(n) ] X = 0 //initialize object vector (array) cu = M //remaining knapsack capacity for i = 1 to n do if W(i) >cu then Exit X(i) = 1 cu = cu – W(i) if i<=n then X(i) = cu/W(i) Data Structure and Algorithm