Richard Anderson Autumn 2019 Lecture 8 – Greedy Algorithms II

Slides:



Advertisements
Similar presentations
 Review: The Greedy Method
Advertisements

CPE555A: Real-Time Embedded Systems
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.
Lecture 24 Coping with NPC and Unsolvable problems. When a problem is unsolvable, that's generally very bad news: it means there is no general algorithm.
Instructor Neelima Gupta Table of Contents Greedy Algorithms.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 7: Greedy Algorithms
CSE 421 Algorithms Richard Anderson Lecture 6 Greedy Algorithms.
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.
Bold Stroke January 13, 2003 Advanced Algorithms CS 539/441 OR In Search Of Efficient General Solutions Joe Hoffert
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. 8.
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.
CSCI1600: Embedded and Real Time Software Lecture 24: Real Time Scheduling II Steven Reiss, Fall 2015.
1 Chapter 5-1 Greedy Algorithms Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
CSEP 521 Applied Algorithms Richard Anderson Winter 2013 Lecture 3.
CSE 421 Algorithms Richard Anderson Lecture 8 Optimal Caching Dijkstra’s algorithm.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 10.
CSE 421 Algorithms Richard Anderson Lecture 8 Greedy Algorithms: Homework Scheduling and Optimal Caching.
Lecture 9 CSE 331 June 18, The “real” end of Semester blues MondayTuesdayWednesdayThursdayFriday Project 331 HW Exam study Party! Write up a term.
Richard Anderson Lecture 26 NP-Completeness
Richard Anderson Lecture 26 NP-Completeness
Lecture 7 Greedy Algorithms
Greedy Algorithms Basic idea Connection to dynamic programming
CprE 458/558: Real-Time Systems
Chapter 4 Greedy Algorithms
Greedy Algorithms / Interval Scheduling Yin Tat Lee
Presented by Po-Chuan & Chen-Chen 2016/03/08
Greedy Algorithms.
Greedy Algorithms / Caching Problem Yin Tat Lee
Lecture 21 CSE 331 Oct 21, 2016.
Richard Anderson Autumn 2015 Lecture 8 – Greedy Algorithms II
Richard Anderson Lecture 25 NP-Completeness
Lecture 21 CSE 331 Oct 20, 2017.
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.
Lecture 20 CSE 331 Oct 14, 2016.
Autumn 2016 Lecture 9 Dijkstra’s algorithm
Autumn 2015 Lecture 9 Dijkstra’s algorithm
CSCI1600: Embedded and Real Time Software
Richard Anderson Lecture 9 Dijkstra’s algorithm
CSCI1600: Embedded and Real Time Software
CSE 421 Richard Anderson Autumn 2016, Lecture 3
Greedy Algorithms: Homework Scheduling and Optimal Caching
Richard Anderson Lecture 6 Greedy Algorithms
Greedy Algorithms / Caching Problem Yin Tat Lee
CSE 421 Richard Anderson Autumn 2015, Lecture 3
Lecture 19 CSE 331 Oct 8, 2014.
Richard Anderson Autumn 2016 Lecture 7
CSCI1600: Embedded and Real Time Software
Lecture 22 CSE 331 Oct 15, 2014.
Lecture 18 CSE 331 Oct 9, 2017.
Richard Anderson Lecture 7 Greedy Algorithms
Richard Anderson Winter 2019 Lecture 8 – Greedy Algorithms II
Lecture 20 CSE 331 Oct 13, 2017.
Lecture 21 CSE 331 Oct 19, 2011.
Richard Anderson Autumn 2016 Lecture 8 – Greedy Algorithms II
Winter 2019 Lecture 9 Dijkstra’s algorithm
Richard Anderson Winter 2019 Lecture 7
CSE 421, University of Washington, Autumn 2006
Merge Sort 5/2/2019 7:53 PM The Greedy Method The Greedy Method.
Week 2: Greedy Algorithms
Lecture 19 CSE 331 Oct 10, 2016.
Richard Anderson Autumn 2015 Lecture 7
Analysis of Algorithms CS 477/677
Richard Anderson Autumn 2019 Lecture 7
CSE 421 Richard Anderson Autumn 2019, Lecture 3
Autumn 2019 Lecture 9 Dijkstra’s algorithm
Autumn 2019 Lecture 11 Minimum Spanning Trees (Part II)
Presentation transcript:

Richard Anderson Autumn 2019 Lecture 8 – Greedy Algorithms II CSE 421 Algorithms Richard Anderson Autumn 2019 Lecture 8 – Greedy Algorithms II

Announcements Today’s lecture Next week Kleinberg-Tardos, 4.2, 4.3

Scheduling Intervals Given a set of intervals What is the largest set of non-overlapping intervals What is the minimum number of processors required to schedule all intervals Suppose the n intervals are “random” What is the expected number of independent intervals What is the expected depth

Generating a random set of intervals Method 1: Each interval assigned random start position in [0.0, 1.0] Each interval assigned a random length in [0.0, 1.0] Method 2: Start with the array [1, 1, 2, 2, 3, 3, 4, 4, 5, 5] Randomly permute it [2, 1, 4, 2, 3, 4, 5, 1, 3, 5] Index of the first j is the start of interval j, and the index of the second j is the end of interval j

Greedy Algorithms Solve problems with the simplest possible algorithm The hard part: showing that something simple actually works Today’s problems (Sections 4.2, 4.3) Homework Scheduling Optimal Caching Subsequence testing

Homework Scheduling Tasks to perform Deadlines on the tasks Freedom to schedule tasks in any order Can I get all my work turned in on time? If I can’t get everything in, I want to minimize the maximum lateness

Scheduling tasks Each task has a length ti and a deadline di All tasks are available at the start One task may be worked on at a time All tasks must be completed Goal minimize maximum lateness Lateness: Li = fi – di if fi >= di

Example Time Deadline 2 a1 2 a2 3 4 2 3 Lateness 1 3 2 Lateness 3

Determine the minimum lateness Show the schedule 2, 3, 4, 5 first and compute lateness Time Deadline 6 2 a1 a2 3 4 a3 4 5 a4 5 12

Greedy Algorithm Earliest deadline first Order jobs by deadline This algorithm is optimal This result may be surprising, since it ignores the job lengths

Analysis Suppose the jobs are ordered by deadlines, d1 <= d2 <= . . . <= dn A schedule has an inversion if job j is scheduled before i where j > i The schedule A computed by the greedy algorithm has no inversions. Let O be the optimal schedule, we want to show that A has the same maximum lateness as O

List the inversions Time Deadline a1 3 4 a2 4 5 a3 2 6 a4 5 12 a4 a2

Lemma: There is an optimal schedule with no idle time It doesn’t hurt to start your homework early! Note on proof techniques This type of can be important for keeping proofs clean It allows us to make a simplifying assumption for the remainder of the proof

Lemma If there is an inversion i, j, there is a pair of adjacent jobs i’, j’ which form an inversion

Interchange argument Suppose there is a pair of jobs i and j, with di <= dj, and j scheduled immediately before i. Interchanging i and j does not increase the maximum lateness. j i i j di dj di dj

Proof by Bubble Sort d1 d2 d3 d4 a2 a4 a3 a1 a2 a4 a1 a3 a2 a1 a4 a3 Determine maximum lateness

Real Proof There is an optimal schedule with no inversions and no idle time. Let O be an optimal schedule k inversions, we construct a new optimal schedule with k-1 inversions Repeat until we have an optimal schedule with 0 inversions This is the solution found by the earliest deadline first algorithm

Result Earliest Deadline First algorithm constructs a schedule that minimizes the maximum lateness

Homework Scheduling How is the model unrealistic?

Extensions What if the objective is to minimize the sum of the lateness? EDF does not work If the tasks have release times and deadlines, and are non-preemptable, the problem is NP-complete What about the case with release times and deadlines where tasks are preemptable?

Optimal Caching Caching problem: Maintain collection of items in local memory Minimize number of items fetched

Caching example A, B, C, D, A, E, B, A, D, A, C, B, D, A

Optimal Caching If you know the sequence of requests, what is the optimal replacement pattern? Note – it is rare to know what the requests are in advance – but we still might want to do this: Some specific applications, the sequence is known Register allocation in code generation Competitive analysis, compare performance on an online algorithm with an optimal offline algorithm

Farthest in the future algorithm Discard element used farthest in the future A, B, C, A, C, D, C, B, C, A, D

Correctness Proof Sketch Start with Optimal Solution O Convert to Farthest in the Future Solution F-F Look at the first place where they differ Convert O to evict F-F element There are some technicalities here to ensure the caches have the same configuration . . .

Subsequence Testing Is a1a2…am a subsequence of b1b2…bn ? e.g. is T,R,E,E a subsequence of S,T,U,A,R,T,R,E,G,E,S T R E E S T U A R T R E G E S

Next week