Algorithm Design and Analysis

Similar documents
Algorithm Design and Analysis

4. GREEDY ALGORITHMS I

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides.

Arrow s Impossibility Theorem

Arrow s Impossibility Theorem

CS 573 Automata Theory and Formal Languages

Review of Gaussian Quadrature method

Exercise sheet 6: Solutions

Chapter 4 State-Space Planning

CS 491G Combinatorial Optimization Lecture Notes

Greedy Algorithms. Greedy Algorithms. Piyush Kumar

Nondeterministic Automata vs Deterministic Automata

For a, b, c, d positive if a b and. ac bd. Reciprocal relations for a and b positive. If a > b then a ab > b. then

AP Calculus BC Chapter 8: Integration Techniques, L Hopital s Rule and Improper Integrals

6.5 Improper integrals

Improper Integrals. The First Fundamental Theorem of Calculus, as we ve discussed in class, goes as follows:

Lecture 3 ( ) (translated and slightly adapted from lecture notes by Martin Klazar)

Golden Section Search Method - Theory

Section 1.3 Triangles

Introduction to Olympiad Inequalities

QUADRATIC EQUATION. Contents

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

System Validation (IN4387) November 2, 2012, 14:00-17:00

Convert the NFA into DFA

Lecture 6: Coding theory

Project 6: Minigoals Towards Simplifying and Rewriting Expressions

NON-DETERMINISTIC FSA

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

Preview 11/1/2017. Greedy Algorithms. Coin Change. Coin Change. Coin Change. Coin Change. Greedy algorithms. Greedy Algorithms

Solutions to Assignment 1

INTEGRATION. 1 Integrals of Complex Valued functions of a REAL variable

MA123, Chapter 10: Formulas for integrals: integrals, antiderivatives, and the Fundamental Theorem of Calculus (pp.

Probability. b a b. a b 32.

More Properties of the Riemann Integral

Part 4. Integration (with Proofs)

Bases for Vector Spaces

University of Sioux Falls. MAT204/205 Calculus I/II

T b a(f) [f ] +. P b a(f) = Conclude that if f is in AC then it is the difference of two monotone absolutely continuous functions.

Solutions for HW9. Bipartite: put the red vertices in V 1 and the black in V 2. Not bipartite!

Connected-components. Summary of lecture 9. Algorithms and Data Structures Disjoint sets. Example: connected components in graphs

Nondeterminism and Nodeterministic Automata

Homework 3 Solutions

CS241 Week 6 Tutorial Solutions

Alpha Algorithm: Limitations

Tutorial Worksheet. 1. Find all solutions to the linear system by following the given steps. x + 2y + 3z = 2 2x + 3y + z = 4.

Beginning Darboux Integration, Math 317, Intro to Analysis II

Welcome. Balanced search trees. Balanced Search Trees. Inge Li Gørtz

THE EXISTENCE-UNIQUENESS THEOREM FOR FIRST-ORDER DIFFERENTIAL EQUATIONS.

CS 188: Artificial Intelligence Spring 2007

Counting Paths Between Vertices. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs

Mid-Term Examination - Spring 2014 Mathematical Programming with Applications to Economics Total Score: 45; Time: 3 hours

Exercises with (Some) Solutions

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

A Lower Bound for the Length of a Partial Transversal in a Latin Square, Revised Version

CS103 Handout 32 Fall 2016 November 11, 2016 Problem Set 7

Discrete Structures Lecture 11

Linear Inequalities. Work Sheet 1

Formal Methods in Software Engineering

2.4 Linear Inequalities and Interval Notation

1 Nondeterministic Finite Automata

Minimal DFA. minimal DFA for L starting from any other

Designing finite automata II

Lecture 3. In this lecture, we will discuss algorithms for solving systems of linear equations.

Technische Universität München Winter term 2009/10 I7 Prof. J. Esparza / J. Křetínský / M. Luttenberger 11. Februar Solution

22: Union Find. CS 473u - Algorithms - Spring April 14, We want to maintain a collection of sets, under the operations of:

Factorising FACTORISING.

Intermediate Math Circles Wednesday 17 October 2012 Geometry II: Side Lengths

QUADRATIC EQUATION EXERCISE - 01 CHECK YOUR GRASP

p-adic Egyptian Fractions

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3

] dx (3) = [15x] 2 0

Topics Covered AP Calculus AB

Data Structures and Algorithms CMPSC 465

Algorithms & Data Structures Homework 8 HS 18 Exercise Class (Room & TA): Submitted by: Peer Feedback by: Points:

Spacetime and the Quantum World Questions Fall 2010

AP CALCULUS Test #6: Unit #6 Basic Integration and Applications

Chapter 5 Plan-Space Planning

Chapter 2 Finite Automata

MAT 403 NOTES 4. f + f =

Computational Biology Lecture 18: Genome rearrangements, finding maximal matches Saad Mneimneh

Now we must transform the original model so we can use the new parameters. = S max. Recruits

15-451/651: Design & Analysis of Algorithms December 3, 2013 Lecture #28 last changed: November 28, 2013

1 The fundamental theorems of calculus.

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

CSE 332. Sorting. Data Abstractions. CSE 332: Data Abstractions. QuickSort Cutoff 1. Where We Are 2. Bounding The MAXIMUM Problem 4

Fingerprint idea. Assume:

Logic, Set Theory and Computability [M. Coppenbarger]

Designing Information Devices and Systems I Spring 2018 Homework 7

First Midterm Examination

1 Probability Density Functions

Symmetrical Components 1

Riemann Sums and Riemann Integrals

CS 188 Introduction to Artificial Intelligence Fall 2018 Note 7

Section 6.1 Definite Integral

W. We shall do so one by one, starting with I 1, and we shall do it greedily, trying

Suppose we want to find the area under the parabola and above the x axis, between the lines x = 2 and x = -2.

Functions. mjarrar Watch this lecture and download the slides

12.4 Similarity in Right Triangles

The Minimum Label Spanning Tree Problem: Illustrating the Utility of Genetic Algorithms

CS 330 Formal Methods and Models

Transcription:

Algorithm Design nd Anlysis LECTURE 5 Supplement Greedy Algorithms Cont d Minimizing lteness Ching (NOT overed in leture) Adm Smith 9/8/10 A. Smith; sed on slides y E. Demine, C. Leiserson, S. Rskhodnikov, K. Wyne

Greedy Algorithms Build up solution to n optimiztion prolem t eh step shortsightedly hoosing the option tht urrently seems the est. Sometimes good Often does not work Proving orretness n e triky, euse lgorithm is unstrutured 9/8/10 A. Smith; sed on slides y E. Demine, C. Leiserson, S. Rskhodnikov, K.

Lst leture (KT, Chpter 4.1) Two types of orretness rguments Greedy stys hed Intervl sheduling prolem d e f g Struturl rgument Intervl prtitioning 4 3 0 1 2 3 4 5 6 7 8 9 1 0 e d g h 1 1 j Time 2 h 1 f i Tody: exhnge 9 9:3 0 1 0 10:30 1 1 11:30 1 2 12:30 1 1:3 0 2 2:3 0 3 3:3 0 4 4:3 0 9/8/10 A. Smith; sed on slides y E. Demine, C. Leiserson, S. Rskhodnikov, K.

Sheduling to minimize lteness 9/8/10 A. Smith; sed on slides y E. Demine, C. Leiserson, S. Rskhodnikov, K. Wyne

Sheduling to Minimizing Lteness Minimizing lteness prolem. Single resoure proesses one jo t time. Jo j requires t j units of proessing time nd is due t time d j. If j strts t time s j, it finishes t time f j = s j + t j. Lteness: j = mx { 0, f j - d j }. Gol: shedule ll jos to minimize mximum lteness L = mx j. Ex: 1 2 3 4 5 6 t j 3 2 1 4 3 2 d j 6 8 9 9 14 15 lteness = 2 lteness = 0 mx lteness = 6 d 3 = 9 d 2 = 8 d 6 = 15 d 1 = 6 d 5 = 14 d 4 = 9 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Greedy strtegies?

Minimizing Lteness: Greedy Algorithms Greedy templte. Consider jos in some order. [Shortest proessing time first] Consider jos in sending order of proessing time t j. [Erliest dedline first] Consider jos in sending order of dedline d j. [Smllest slk] Consider jos in sending order of slk d j - t j.

Minimizing Lteness: Greedy Algorithms Greedy templte. Consider jos in some order. [Shortest proessing time first] Consider jos in sending order of proessing time t j. t j 1 100 d j 1 2 10 10 ounterexmple [Smllest slk] Consider jos in sending order of slk d j - t j. 1 t j 1 2 d j 2 10 10 ounterexmple

Minimizing Lteness: Greedy Algorithm Greedy lgorithm. Erliest dedline first. Sort n jos y dedline so tht d 1 d 2 d n t 0 for j = 1 to n Assign jo j to intervl [t, t + t j ] s j t, f j t + t j t t + t j output intervls [s j, f j ] mx lteness = 1 d 1 = 6 d 2 = 8 d 3 = 9 d 4 = 9 d 5 = 14 d 6 = 15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Minimizing Lteness: No Idle Time Oservtion. There exists n optiml shedule with no idle time. d = 4 d = 6 0 1 2 3 4 5 6 d = 12 7 8 9 10 11 d = 4 d = 6 d = 12 0 1 2 3 4 5 6 7 8 9 10 11 Oservtion. The greedy shedule hs no idle time.

Minimizing Lteness: Inversions Def. An inversion in shedule S is pir of jos i nd j suh tht: i < j ut j sheduled efore i. inversion efore swp j i Oservtion. Greedy shedule hs no inversions. Oservtion. If shedule (with no idle time) hs n inversion, it hs one with pir of inverted jos sheduled onseutively.

Minimizing Lteness: Inversions Def. An inversion in shedule S is pir of jos i nd j suh tht: i < j ut j sheduled efore i. inversion f i efore swp j i fter swp i j f' j Clim. Swpping two djent, inverted jos redues the numer of inversions y one nd does not inrese the mx lteness. Pf. Let e the lteness efore the swp, nd let ' e it fterwrds. ' k = k for ll k i, j ' i i If jo j is lte: j f d j f d i f d i i j i j (definition) ( j finishes t time f ) ( i j ) (definition) i

Minimizing Lteness: Anlysis of Greedy Algorithm Theorem. Greedy shedule S is optiml. Pf. Define S* to e n optiml shedule tht hs the fewest numer of inversions, nd let's see wht hppens. Cn ssume S* hs no idle time. If S* hs no inversions, then S = S*. If S* hs n inversion, let i-j e n djent inversion. swpping i nd j does not inrese the mximum lteness nd stritly dereses the numer of inversions this ontrdits definition of S*

Greedy Anlysis Strtegies Greedy lgorithm stys hed. Show tht fter eh step of the greedy lgorithm, its solution is t lest s good s ny other lgorithm's. Exhnge rgument. Grdully trnsform ny solution to the one found y the greedy lgorithm without hurting its qulity. Struturl. Disover simple "struturl" ound sserting tht every possile solution must hve ertin vlue. Then show tht your lgorithm lwys hieves this ound.

Optiml Ching 9/8/10 A. Smith; sed on slides y E. Demine, C. Leiserson, S. Rskhodnikov, K. Wyne

Optiml Offline Ching Ching. Che with pity to store k items. Sequene of m item requests d 1, d 2,, d m. Che hit: item lredy in he when requested. Che miss: item not lredy in he when requested: must ring requested item into he, nd evit some existing item, if full. Gol. Evition shedule tht minimizes numer of he misses. Ex: k = 2, initil he =, requests:,,,,,,,. Optiml evition shedule: 2 he misses. requests he

Suggestions for greedy pprohes?

Optiml Offline Ching: Frthest-In-Future Frthest-in-future. Evit item in the he tht is not requested until frthest in the future. urrent he: d e f future queries: g e d d e f d e f g h... he miss ejet this one Theorem. [Belldy, 1960s] FF is optiml evition shedule. Pf. Algorithm nd theorem re intuitive; proof is sutle.

Redued Evition Shedules Def. A redued shedule is shedule tht only inserts n item into the he in step in whih tht item is requested. Intuition. Cn trnsform n unredued shedule into redued one with no more he misses. (Ide is to defer unredued requests. Proof will e n exerise.) x d d d d d d x d n unredued shedule redued shedule

Frthest-In-Future: Anlysis Theorem. FF is optiml evition lgorithm. Pf. (y indution on numer or requests j) Invrint: There exists n optiml redued shedule S tht mkes the sme evition shedule s S FF through the first j+1 requests. Let S = opt. redued shedule tht stisfies invrint through j requests. We produe S' tht stisfies invrint fter j+1 requests. Consider (j+1) st request d = d j+1. Sine S nd S FF hve greed up until now, they hve the sme he ontents efore request j+1. Cse 1: (d is lredy in the he). S' = S stisfies invrint. Cse 2: (d is not in the he nd S nd S FF evit the sme element). S' = S stisfies invrint.

Frthest-In-Future: Anlysis Pf. (ontinued) Cse 3: (d is not in the he; S FF evits e; S evits f e). egin onstrution of S' from S y eviting e insted of f j sme e f sme e f S S' j+1 j sme e d sme d f S S' now S' grees with S FF on first j+1 requests; we show tht hving element f in he is no worse thn hving element e

Frthest-In-Future: Anlysis Let j' e the first time fter j+1 tht S nd S' tke different tion, nd let g e item requested t time j'. must involve e or f (or oth) j' sme e sme f S S' Cse 3: g = e. Cn't hppen with Frthest-In-Future sine there must e request for f efore e. Cse 3: g = f. Element f n't e in he of S, so let e' e the element tht S evits. if e' = e, S' esses f from he; now S nd S' hve sme he if e' e, S' evits e' nd rings e into the he; now S nd S' hve the sme he Note: S' is no longer redued, ut n e trnsformed into redued shedule tht grees with S FF through step j+1

Frthest-In-Future: Anlysis Let j' e the first time fter j+1 tht S nd S' tke different tion, nd let g e item requested t time j'. must involve e or f (or oth) j' sme e sme f S S' otherwise S' would tke the sme tion Cse 3: g e, f. S must evit e. Mke S' evit f; now S nd S' hve the sme he. j' sme g sme g S S'

Ching Perspetive Online vs. offline lgorithms. Offline: full sequene of requests is known priori. Online (relity): requests re not known in dvne. Ching is mong most fundmentl online prolems in CS. LIFO. Evit pge rought in most reently. LRU. Evit pge whose most reent ess ws erliest. FF with diretion of time reversed! Theorem. FF is optiml offline evition lgorithm. Provides sis for understnding nd nlyzing online lgorithms. LRU is k-ompetitive. [Setion 13.8] LIFO is ritrrily d.