greedy algorithms
play

Greedy Algorithms Solve problems with the simplest possible - PDF document

Greedy Algorithms Solve problems with the simplest possible algorithm CSE 421 The hard part: showing that something Algorithms simple actually works Pseudo-definition Richard Anderson An algorithm is Greedy if it builds its


  1. Greedy Algorithms • Solve problems with the simplest possible algorithm CSE 421 • The hard part: showing that something Algorithms simple actually works • Pseudo-definition Richard Anderson – An algorithm is Greedy if it builds its solution Lecture 7 by adding elements one at a time using a Greedy Algorithms simple rule Scheduling Theory Interval Scheduling • Tasks • Tasks occur at fixed times – Processing requirements, release times, • Single processor deadlines • Maximize number of tasks completed • Processors • Precedence constraints • Objective function • Tasks {1, 2, . . . N} – Jobs scheduled, lateness, total execution time • Start and finish times, s(i), f(i) What is the largest solution? Greedy Algorithm for Scheduling Let T be the set of tasks, construct a set of independent tasks I, A is the rule determining the greedy algorithm I = { } While (T is not empty) Select a task t from T by a rule A Add t to I Remove t and all tasks incompatible with t from T 1

  2. Simulate the greedy algorithm for Greedy solution based on earliest each of these heuristics finishing time Schedule earliest starting task Example 1 Schedule shortest available task Example 2 Schedule task with fewest conflicting tasks Example 3 Theorem: Earliest Finish Algorithm Stay ahead lemma is Optimal • Key idea: Earliest Finish Algorithm stays • A always stays ahead of B, f(i r ) <= f(j r ) ahead • Induction argument • Let A = {i 1 , . . ., i k } be the set of tasks found – f(i 1 ) <= f(j 1 ) by EFA in increasing order of finish times – If f(i r-1 ) <= f(j r-1 ) then f(i r ) <= f(j r ) • Let B = {j 1 , . . ., j m } be the set of tasks found by a different algorithm in increasing order of finish times • Show that for r<= min(k, m), f(i r ) <= f(j r ) Completing the proof Scheduling all intervals • Let A = {i 1 , . . ., i k } be the set of tasks found by • Minimize number of processors to EFA in increasing order of finish times schedule all intervals • Let O = {j 1 , . . ., j m } be the set of tasks 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 tasks 2

  3. How many processors are needed Prove that you cannot schedule this set for this example? of intervals with two processors Depth: maximum number of Algorithm intervals active • Sort by start times • Suppose maximum depth is d, create d slots • Schedule items in increasing order, assign each item to an open slot • Correctness proof: When we reach an item, we always have an open slot Scheduling tasks Example Time Deadline • Each task has a length t i and a deadline d i 2 2 • All tasks are available at the start 3 4 • One task may be worked on at a time • All tasks must be completed Lateness 1 2 3 • Goal minimize maximum lateness – Lateness = f i – d i if f i >= d i 3 2 Lateness 3 3

  4. To be continued . . . Determine the minimum lateness Time Deadline 6 2 3 4 4 5 5 12 4

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend