DS-chapter10&iuml;&frac14;ˆGreedy&iuml;&frac14;ŒDivide and Conquer)

# DS-chapter10ï¼ˆGreedyï¼ŒDivide and Conquer)

This preview shows pages 1–6. Sign up to view the full content.

CHAPTER 10 ALGORITHM DESIGN TECHNIQUES 10.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 .

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
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. 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 Given N jobs j 1 , j 2 , …, j N , their running times t 1 , t 2 , …, t N , and one processor. Schedule jobs to minimize the average completion time. /* assume nonpreemptive scheduling */ The Single Processor Case
Greedy Algorithms 〖 Example 〖 job time j 1 j 2 j 3 j 4 15 8 3 10 Schedule 1 j 1 0 15 j 2 23 j 3 26 j 4 36 T avg = ( 15 + 23 + 26 + 36 ) / 4 = 25 Schedule 2 j 1 36 j 2 11 0 j 3 3 j 4 21 T avg = ( 3 + 11 + 21 + 36 ) / 4 = 17.75 In general: 0 j i 1 t i 1 j i 2 t i 1 + t i 2 j i 3 t i 1 + t i 2 + t i 3 … … = = = - + = + - = N k i N k i N k i k k k t k t N t k N C 1 1 1 ) 1 ( ) 1 ( Cost Total Best scheduling is to make { t ik } nondecreasing .

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Greedy Algorithms The Multiprocessor Case N jobs on P processors 〖 Example 〖 P = 3 job time j 1 j 2 j 3 j 4 3 5 6 10 j 5 j 6 j 7 j 8 11 14 15 18 j 9 20 An Optimal Solution j 1 3 j 2 5 j 3 6 0 j 4 13 j 5 16 j 6 20 j 7 28 j 8 34 j 9 40 Another Optimal Solution j 1 3 j 2 5 j 3 6 0 j 4 15 j 5 14 j 6 20 j 7 30 j 8 38 j 9 34 Minimizing the Final Completion Time NP Hard An Optimal Solution j 1 3 j 2 5 j 3 9 j 4 19 j 5 16 j 6 14 j 7 j 8 34 j 9 0
Greedy Algorithms 2. Huffman Codes – for file compression 〖 Example 〖 Suppose our text is a string of length 1000 that comprises the characters a , u , x , and z . Then it will take ? bits to store the string as 1000 one-byte characters. 8000 Notice that we have only 4 distinct characters in that string. Hence we need only 2 bits to identify them. We may encode the symbols as a = 00 , u = 01 , x = 10 , z = 11 . For example, aaa x u a x z is encoded as 000000 10 01 00 10 11 . Then the space taken by the string with length 1000 will be 2000 bits + space for code table.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 24

DS-chapter10ï¼ˆGreedyï¼ŒDivide and Conquer)

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online