Download presentation

Published byMakaila Parkhill Modified over 4 years ago

1
**§1 Greedy Algorithms ALGORITHM DESIGN TECHNIQUES**

CHAPTER 10 ALGORITHM DESIGN TECHNIQUES §1 Greedy Algorithms Optimization Problems: Given a set of constrains and an optimization function. Solutions that satisfy the constrains are called feasible solutions. A feasible solution for which the optimization function has the best possible value is called an optimal solution. The Greedy Method: Make the best decision at each stage, under some greedy criterion. A decision made in one stage is not changed in a later stage, so each decision should assure feasibility. 1/7

2
**1. A Simple Scheduling Problem**

§1 Greedy Algorithms Note: Greedy algorithm works only if the local optimum is equal to the global optimum. Greedy algorithm does not guarantee optimal solutions. However, it generally produces solutions that are very close in value (heuristics) to the optimal, and hence is intuitively appealing when finding the optimal solution takes too much time. 1. A Simple Scheduling Problem The Single Processor Case Given N jobs j1 , j2 , …, jN , their running times t1 , t2 , …, tN , and one processor. Schedule jobs to minimize the average completion time. /* assume nonpreemptive scheduling */ 2/7

3
**Best scheduling is to make { tik } nondecreasing.**

§1 Greedy Algorithms 〖Example〗 job time j1 j2 j3 j4 15 8 3 10 Schedule 1 j1 15 j2 23 j3 26 j4 36 Best scheduling is to make { tik } nondecreasing. Tavg = ( ) / 4 = 25 Schedule 2 j3 3 j2 11 j4 21 j1 36 Tavg = ( ) / 4 = 17.75 In general: ji1 ti1 ji2 ti1 + ti2 ji3 ti1 + ti2 + ti3 … … 3/7

4
** The Multiprocessor Case – N jobs on P processors**

§1 Greedy Algorithms The Multiprocessor Case – N jobs on P processors 〖Example〗 P = 3 job time j1 j2 j3 j4 3 5 6 10 j5 j6 j7 j8 11 14 15 18 j9 20 An Optimal Solution Another Optimal Solution j1 3 j2 5 j3 6 j4 15 j5 14 j6 20 j7 30 j8 38 j9 34 j1 3 j4 13 j7 28 j2 5 j5 16 j8 34 j3 6 j6 20 j9 40 Minimizing the Final Completion Time An Optimal Solution j1 3 j2 5 j3 9 j4 19 j5 16 j6 14 j7 j8 34 j9 NP Hard 4/7

5
** jij must be processed by Pj and the processing time is tij . **

§1 Greedy Algorithms Flow Shop Scheduling – a simple case with 2 processors Consider a machine shop that has 2 identical processors P1 and P2 . We have N jobs J1, ... , JN that need to be processed. Each job Ji can be broken into 2 tasks ji1 and ji2 . If there is an ai = 0, then we can schedule all the jobs with aj 0 first. Then we insert the jobs with ai = 0 to the front of the schedule list in arbitrary order. A schedule is an assignment of jobs to time intervals on machines such that jij must be processed by Pj and the processing time is tij . No machine processes more than one job at any time. ji2 may not be started before ji1 is finished. Construct a minimum-completion-time 2 machine schedule for a given set of N jobs. Let ai = ti1 0, and bi = ti2 . 〖Example〗 Given N = 4, T1234 = ? 40 5/7

6
**【Proposition】 An optimal schedule exists if min { bi , aj } **

§1 Greedy Algorithms 【Proposition】 An optimal schedule exists if min { bi , aj } min { bj , ai } for any pair of adjacent jobs Ji and Jj . All the schedules with this property have the same completion time. Algorithm { Sort { a1 , ... , aN , b1 , ... , bN } into non-decreasing sequence ; m = minimum element ; do { if ( ( m == ai ) && ( Ji is not in the schedule ) ) Place Ji at the left-most empty position ; else if ( ( m == bj ) && ( Jj is not in the schedule ) ) Place Jj at the right-most empty position ; m = next minimum element ; } while ( m ); } T = O( N log N ) 〖Example〗 Given N = 4, J1 J3 J4 J2 Sorting { b2 a1 a2 b1 a3 b3 a4 b4 } T1342 = ? 38 6/7

7
**Due: Monday, January 15th, 2006 at 10:00pm**

§1 Greedy Algorithms Bonus Problem 1 The Best ACT Due: Monday, January 15th, 2006 at 10:00pm Detailed requirements can be downloaded from Courseware Download Hint: Carefully consider the range of integers to avoid RunTime Error. 7/7

Similar presentations

Presentation is loading. Please wait....

OK

Essential Cell Biology

Essential Cell Biology

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on feedback amplifier Working of flat panel display ppt on tv Ppt on image sensor Ppt on electric arc furnace Ppt on acid-base indicators color change Ppt on water pollution in hindi language Ppt on natural resources of india Ppt on bill gates leadership Download ppt on teamviewer 9 Ppt on 600 mw generator