CSE 421 Algorithms Richard Anderson Lecture 8 Greedy Algorithms: Homework Scheduling and Optimal Caching.

Slides:



Advertisements
Similar presentations
 Review: The Greedy Method
Advertisements

1 Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
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.
Online Scheduling with Known Arrival Times Nicholas G Hall (Ohio State University) Marc E Posner (Ohio State University) Chris N Potts (University of Southampton)
Clustering and greedy algorithms — Part 2 Prof. Noah Snavely CS1114
CSE 421 Algorithms Richard Anderson Lecture 6 Greedy Algorithms.
CSE 421 Algorithms Richard Anderson Lecture 10 Minimum Spanning Trees.
Ecole Polytechnique, Nov 7, Online Job Scheduling Marek Chrobak University of California, Riverside.
Lecture 24 CSE 331 Oct 27, Online office hours tonight 9:00pm.
Clustering and greedy algorithms Prof. Noah Snavely CS1114
1 The Greedy Method CSC401 – Analysis of Algorithms Lecture Notes 10 The Greedy Method Objectives Introduce the Greedy Method Use the greedy method to.
10/31/02CSE Greedy Algorithms CSE Algorithms Greedy Algorithms.
Lecture 22 CSE 331 Oct 26, Blog posts Please sign up if you have not If I have a pick a blogger I will only pick ONE/lecture Will lose out on 5%
10/31/02CSE Greedy Algorithms CSE Algorithms Greedy Algorithms.
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.
Image segmentation Prof. Noah Snavely CS1114
CSE 331: Review. Main Steps in Algorithm Design Problem Statement Algorithm Real world problem Problem Definition Precise mathematical def “Implementation”
1 Short Term Scheduling. 2  Planning horizon is short  Multiple unique jobs (tasks) with varying processing times and due dates  Multiple unique jobs.
CSE 5314 On-line Computation Homework 1 Wook Choi Feb/26/2004.
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.
CSCI1600: Embedded and Real Time Software Lecture 23: Real Time Scheduling I Steven Reiss, Fall 2015.
1 Chapter 5-1 Greedy Algorithms Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Dynamic Programming.  Decomposes a problem into a series of sub- problems  Builds up correct solutions to larger and larger sub- problems  Examples.
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.
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.
Spring 2008The Greedy Method1. Spring 2008The Greedy Method2 Outline and Reading The Greedy Method Technique (§5.1) Fractional Knapsack Problem (§5.1.1)
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 27 NP-Completeness Proofs.
Lecture 9 CSE 331 June 18, The “real” end of Semester blues MondayTuesdayWednesdayThursdayFriday Project 331 HW Exam study Party! Write up a term.
Greedy Algorithms.
Richard Anderson Lecture 26 NP-Completeness
IGCSE 6 Cambridge Effectiveness of algorithms Computer Science
Richard Anderson Lecture 26 NP-Completeness
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
Lecture 21 CSE 331 Oct 20, 2017.
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
Greedy Algorithms: Homework Scheduling and Optimal Caching
Richard Anderson Lecture 6 Greedy Algorithms
Greedy Algorithms / Caching Problem Yin Tat Lee
Richard Anderson Autumn 2016 Lecture 7
CSCI1600: Embedded and Real Time Software
Lecture 22 CSE 331 Oct 15, 2014.
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
Week 2: Greedy Algorithms
Richard Anderson Autumn 2015 Lecture 7
Richard Anderson Autumn 2019 Lecture 7
Richard Anderson Autumn 2019 Lecture 8 – Greedy Algorithms II
Autumn 2019 Lecture 9 Dijkstra’s algorithm
Presentation transcript:

CSE 421 Algorithms Richard Anderson Lecture 8 Greedy Algorithms: Homework Scheduling and Optimal Caching

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

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, I want to minimize the maximum lateness

Scheduling tasks Each task has a length t i and a deadline d i 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 = f i – d i if f i >= d i

Example DeadlineTime Lateness 1 Lateness 3

Determine the minimum lateness DeadlineTime

Greedy Algorithm Earliest deadline first Order jobs by deadline This algorithm is optimal

Analysis Suppose the jobs are ordered by deadlines, d 1 <= d 2 <=... <= d n 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 DeadlineTime a1a1 a2a2 a3a3 a4a4 a4a4 a2a2 a3a3 a1a1

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 a4a4 a2a2 a3a3 a1a1

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 d i <= d j, and j scheduled immediately before i. Interchanging i and j does not increase the maximum lateness. d i d j jiji

Proof by Bubble Sort a4a4 a2a2 a3a3 a1a1 a4a4 a2a2 a3a3 a4a4 a2a2 a3a3 a1a1 a4a4 a2a2 a3a3 a1a1 a1a1 a4a4 a2a2 a3a3 a1a1 Determine maximum lateness d1d1 d2d2 d3d3 d4d4

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 seem to 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 –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 a 1 a 2 …a m a subsequence of b 1 b 2 …b n ? –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