DS-chapter10(Greedy,Divide and Conquer)

DS-chapter10(Greedy,Divide and Conquer)

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

View Full Document Right Arrow Icon
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 .
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 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
Background image of page 2
Greedy Algorithms HExample H 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 .
Background image of page 3

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

View Full DocumentRight Arrow Icon
Greedy Algorithms The Multiprocessor Case N jobs on P processors HExample H 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 6 0 j 4 13 j 5 16 20 j 7 28 j 8 34 40 Another Optimal Solution j 1 3 j 2 5 6 0 j 4 15 j 5 14 20 j 7 30 38 j 9 34 Minimizing the Final Completion Time NP Hard An Optimal Solution 3 j 2 5 9 19 j 5 16 j 6 14 j 8 34 j 9 0
Background image of page 4
Greedy Algorithms 2. Huffman Codes – for file compression HExample H 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. /* log C bits are needed in a standard encoding where C is the size of the character set */ frequency ::= number of occurrences of a symbol. In string
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online