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

Slides:



Advertisements
Similar presentations
Introduction to Algorithms
Advertisements

Greedy Algorithms (Chap. 16)
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
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.
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.
Chapter 5 Fundamental Algorithm Design Techniques.
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.
Chapter 4 The Greedy Approach. Minimum Spanning Tree A tree is an acyclic, connected, undirected graph. A spanning tree for a given graph G=, where E.
Greedy Algorithms Basic idea Connection to dynamic programming
Greedy Algorithms Basic idea Connection to dynamic programming Proof Techniques.
Merge Sort 4/15/2017 6:09 PM The Greedy Method The Greedy Method.
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, 2002 Lecture 2 Tuesday, 9/10/02 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
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.
Analysis of Algorithms
Algorithms: Design and Analysis Summer School 2013 at VIASM: Random Structures and Algorithms Lecture 3: Greedy algorithms Phan Th ị Hà D ươ ng 1.
Data Structures and Algorithms A. G. Malamos
David Luebke 1 10/24/2015 CS 332: Algorithms Greedy Algorithms Continued.
Algorithmics - Lecture 101 LECTURE 10: Greedy technique.
Introduction to Algorithms Chapter 16: Greedy Algorithms.
Greedy Methods and Backtracking Dr. Marina Gavrilova Computer Science University of Calgary Canada.
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.
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.
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.
1 Algorithms CSCI 235, Fall 2015 Lecture 29 Greedy Algorithms.
Greedy Algorithms Lecture 10 Asst. Prof. Dr. İlker Kocabaş 1.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 18.
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.
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
Lecture on Design and Analysis of Computer Algorithm
Algorithm Design Methods
Greedy Algorithms (Chap. 16)
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.
Chapter 16: Greedy algorithms Ming-Te Chi
Advanced Algorithms Analysis and Design
Merge Sort 1/17/2019 3:11 AM The Greedy Method The Greedy Method.
Lecture 6 Topics Greedy Algorithm
Greedy Algorithms TOPICS Greedy Strategy Activity Selection
Chapter 16: Greedy algorithms Ming-Te Chi
Algorithms CSCI 235, Spring 2019 Lecture 29 Greedy Algorithms
Greedy Algorithms Comp 122, Spring 2004.
Algorithm Design Techniques Greedy Approach vs Dynamic Programming
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:

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

1.2 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

1.3 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 s i and finish time f i where s i <= f i. Compatibility: Activities i and j are compatible if the interval [s i, f i ) and [s j, f j ) do not overlap (i.e. s i >= f j or s j >= f i ) Goal: To select a maximum- size set of mutually compatible activities.

1.4 Data Structure and Algorithm Activity Selection Problem (Cont.) Assume that Input activities are sorted by increasing finishing time. [ complexity O(nlg 2 n) ] [ 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 s i >= f j then  A = A U {i}  j = i  return A

1.5 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.

1.6 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??

1.7 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: 1. Greedy Choice Property 2. Optimal Sub Structure

1.8 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.

1.9 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: s i >= f 1 }

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

1.11 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)