Richard Anderson Autumn 2016 Lecture 8 – Greedy Algorithms II

Slides:



Advertisements
Similar presentations
 Review: The Greedy Method
Advertisements

CPE555A: Real-Time Embedded Systems
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.
Lecture 24 CSE 331 Oct 27, Online office hours tonight 9:00pm.
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.
CSE 331: Review. Main Steps in Algorithm Design Problem Statement Algorithm Real world problem Problem Definition Precise mathematical def “Implementation”
CSCI 256 Data Structures and Algorithm Analysis Lecture 6 Some slides by Kevin Wayne copyright 2005, Pearson Addison Wesley all rights reserved, and some.
1 Algorithms & Data Structures for Games Lecture 2A Minor Games Programming.
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.
Lecture 8 CSE 331. Main Steps in Algorithm Design Problem Statement Algorithm Problem Definition “Implementation” Analysis n! Correctness+Runtime Analysis.
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.
CSE 332: NP Completeness, Part II Richard Anderson Spring 2016.
Embedded System Scheduling
Greedy Algorithms.
Richard Anderson Lecture 26 NP-Completeness
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.
Richard Anderson Lecture 26 NP-Completeness
The Greedy Method and Text Compression
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.
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
Richard Anderson Autumn 2006 Lecture 1
CSCI1600: Embedded and Real Time Software
Greedy Algorithms: Homework Scheduling and Optimal Caching
Richard Anderson Lecture 6 Greedy Algorithms
Greedy Algorithms / Caching Problem Yin Tat Lee
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 Winter 2009 Lecture 2
Winter 2019 Lecture 9 Dijkstra’s algorithm
Richard Anderson Winter 2019 Lecture 7
Week 2: Greedy Algorithms
Lecture 19 CSE 331 Oct 10, 2016.
Richard Anderson Autumn 2015 Lecture 7
Richard Anderson Autumn 2019 Lecture 7
Richard Anderson Autumn 2019 Lecture 2
Richard Anderson Autumn 2019 Lecture 8 – Greedy Algorithms II
Autumn 2019 Lecture 9 Dijkstra’s algorithm
Presentation transcript:

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

Announcements Midterm exam, October 31, 2016 In class, closed book

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

Highlights from Last Lecture Interval scheduling Earliest Deadline First Correctness proof: Stay ahead lemma Multiprocessor schedule Available processor algorithm Can always schedule with d processors, where d is the maximum number of intervals active at any time.

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 = fi – di if fi >= di

Example Time Deadline 2 2 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 3 4 4 5 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. S,A,G,E is a subsequence of S,T,U,A,R,T,R,E,G,E,S

Greedy Algorithm for Subsequence Testing

Next week