CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 8.

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.
1 Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Comp 122, Spring 2004 Greedy Algorithms. greedy - 2 Lin / Devi Comp 122, Fall 2003 Overview  Like dynamic programming, used to solve optimization problems.
Greedy Algorithms Greed is good. (Some of the time)
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
CS38 Introduction to Algorithms Lecture 5 April 15, 2014.
1 Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Lecture 23 CSE 331 Oct 24, Temp letter grades assigned See the blog post for more details.
CSE 421 Algorithms Richard Anderson Lecture 6 Greedy Algorithms.
Week 2: Greedy Algorithms
Lecture 20 CSE 331 Oct 21, Algorithm for Interval Scheduling R: set of requests Set A to be the empty set While R is not empty Choose i in R with.
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.
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.
Called as the Interval Scheduling Problem. A simpler version of a class of scheduling problems. – Can add weights. – Can add multiple resources – Can ask.
9/8/10 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Adam Smith Algorithm Design and Analysis L ECTURE 6 Greedy Algorithms.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 17.
CSCI 256 Data Structures and Algorithm Analysis Lecture 6 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
CSEP 521 Applied Algorithms Richard Anderson Winter 2013 Lecture 2.
CSC5101 Advanced Algorithms Analysis
1 Chapter 5-1 Greedy Algorithms Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
1 Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Lecture 8 CSE 331. Main Steps in Algorithm Design Problem Statement Algorithm Problem Definition “Implementation” Analysis n! Correctness+Runtime Analysis.
Greedy Algorithms Interval Scheduling and Fractional Knapsack These slides are based on the Lecture Notes by David Mount for the course CMSC 451 at the.
CSEP 521 Applied Algorithms Richard Anderson Winter 2013 Lecture 3.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 10.
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.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 3.
1 Algorithms CSCI 235, Fall 2015 Lecture 29 Greedy Algorithms.
Greedy Algorithms Lecture 10 Asst. Prof. Dr. İlker Kocabaş 1.
PREPARED BY: Qurat Ul Ain SUBMITTED TO: Ma’am Samreen.
Greedy algorithms: CSC317
Greedy Algorithms.
Greedy Algorithms – Chapter 5
Chapter 4 Greedy Algorithms
Greedy Algorithms Basic idea Connection to dynamic programming
Chapter 4 Greedy Algorithms
Greedy Algorithms / Interval Scheduling Yin Tat Lee
Presented by Po-Chuan & Chen-Chen 2016/03/08
Chapter 4 Greedy Algorithms
Richard Anderson Autumn 2015 Lecture 8 – Greedy Algorithms II
4.1 Interval Scheduling.
Chapter 6 Dynamic Programming
Chapter 6 Dynamic Programming
Chapter 16: Greedy algorithms Ming-Te Chi
Lecture 19 CSE 331 Oct 12, 2016.
Lecture 11 Overview Self-Reducibility.
Lecture 11 Overview Self-Reducibility.
Greedy Algorithms.
Greedy Algorithms: Homework Scheduling and Optimal Caching
Richard Anderson Lecture 6 Greedy Algorithms
Lecture 19 CSE 331 Oct 8, 2014.
Chapter 16: Greedy algorithms Ming-Te Chi
Richard Anderson Autumn 2016 Lecture 7
Lecture 18 CSE 331 Oct 9, 2017.
Richard Anderson Lecture 7 Greedy Algorithms
Algorithms CSCI 235, Spring 2019 Lecture 29 Greedy Algorithms
Richard Anderson Autumn 2016 Lecture 8 – Greedy Algorithms II
Chapter 4 Greedy Algorithms
Richard Anderson Winter 2019 Lecture 7
Week 2: Greedy Algorithms
Lecture 19 CSE 331 Oct 10, 2016.
Richard Anderson Autumn 2015 Lecture 7
Asst. Prof. Dr. İlker Kocabaş
Data Structures and Algorithm Analysis Lecture 8
Richard Anderson Autumn 2019 Lecture 7
Richard Anderson Autumn 2019 Lecture 8 – Greedy Algorithms II
Presentation transcript:

CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 8

Greedy Algorithms Solve problems with the simplest possible algorithm The hard part: showing that something simple actually works Pseudo-definition –An algorithm is Greedy if it builds its solution by adding elements one at a time using a simple rule

Interval Scheduling Interval scheduling –Job j starts at s j and finishes at f j –Two jobs compatible if they don't overlap –Goal: find maximum subset of mutually compatible jobs Time f g h e a b c d

What is the Largest Solution?

Greedy Template Let T be the set of jobs, construct a set of independent jobs A H is the rule (heuristic) determining the greedy algorithm A = { } While (T is not empty) Select a job t from T by a rule H Add t to A Remove t and all jobs incompatible with t from T

Heuristics [Earliest start time] Consider jobs in ascending order of start time s j [Earliest finish time] Consider jobs in ascending order of finish time f j [Shortest interval] Consider jobs in ascending order of interval length f j – s j [Fewest conflicts] For each job, count the number of conflicting jobs c j. Schedule in ascending order of conflicts c j

Simulate greedy algorithm for each of these heuristics Schedule earliest starting job Schedule shortest available job Schedule job with fewest conflicting jobs

Greedy solution based on earliest finishing time Example 1 Example 2 Example 3

Heuristics that don’t work breaks earliest start time breaks shortest interval breaks fewest conflicts

Greedy Algorithm for Interval Scheduling Earliest Finish Algorithm (EFA): Consider jobs in increasing order of finish time. Take each job provided it's compatible with the ones already taken Implementation: O(n log n) –Remember job j* that was added last to A –Job j is compatible with A if s j  f j* Sort jobs by finish times so that f 1  f 2 ...  f n A   for j = 1 to n { if (job j compatible with A) A  A  {j} } return A

Theorem: EFA is Optimal Key idea: EFA stays ahead Let A = {i 1,..., i k } be the set of jobs found by EFA in increasing order of finish times Let B = {j 1,..., j m } be the set of jobs found by a different algorithm in increasing order of finish times Show that for r<= min(k, m), f(i r ) <= f(j r )

Stay Ahead Lemma A always stays ahead of B, f(i r ) <= f(j r ) Induction argument –f(i 1 ) <= f(j 1 ) –If f(i r-1 ) <= f(j r-1 ) then f(i r ) <= f(j r )

Completing the Proof Let A = {i 1,..., i k } be the set of jobs found by EFA in increasing order of finish times Let O = {j 1,..., j m } be the set of jobs found by an optimal algorithm in increasing order of finish times If k < m, then the Earliest Finish Algorithm stopped before it ran out of jobs

Interval Partitioning Interval partitioning –Lecture j starts at s j and finishes at f j –Goal: find minimum number of classrooms to schedule all lectures so that no two occur at the same time in the same room –Ex: This schedule uses 4 classrooms to schedule 10 lectures Time 99:301010:301111:301212:3011:3022:30 h c b a e d g f i j 33:3044:30

Interval Partitioning –Ex: This schedule uses only 3 Time 99:301010:301111:301212:3011:3022:30 h c a e f g i j 33:3044:30 d b

How many processors are needed for this example?