CS300-04_Algorithm_Design - Algorithm Design Sung Yong Shin...

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

View Full Document Right Arrow Icon
1 Algorithm Design Sung Yong Shin CS Dept. KAIST
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 1. Divide and Conquer 2. Dynamic Programming 3. Greedy Search 4. Backtracking 5. Local Search P306 - 346 (Chapter 10) Aho, Hopcroft, and Ulman Outline
Background image of page 2
3 where k is a relatively small constant. Sol ( P ) = f ( Sol ( P 1 ), Sol ( P 2 ), …, Sol ( P k )) Combining the solutions of all subproblems T ( n ) = T ( n 1 ) + T ( n 2 ) + … + T ( n k ) + M ( n ) , where n is the size of P and n i is the size of P i . How can you interpret M ( n ) ? , 1 , 1 k j i P P P P j i i k i < = = = P 1 P 2 P k …... P 1. Divide and Conquer
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 T ( n ) = T ( n 1 ) + T ( n 2 ) + … + T ( n k ) + M ( n ) In general k M ( n ) k M ( n ) Why ? (intuitive explanation) k is usually small i.e., k = 2 or 3 in many cases Can you give some examples ? Well, … Merge sort Binary search …... Observation
Background image of page 4
5 Now, consider the sizes of subproblems. (e.g. k = 2) P = P 1 P 2 P 1 P 2 = n = n 1 + n 2 T( n ) = T( n 1 ) + T( n 2 ) + M( n ) d T( n ) d T( n ) Why ? Size of P 2 Size of P Size of P 1 n 11 n 1 n n 111 n 2 n 12 n 112 ……………………………. ………. . ………. . d
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Example P : Given a set of n real numbers, sort them T ( n ) = T ( n 1 ) + T ( n 2 ) + M ( n ) Selection Sort Merge Sort Selection Sort (1) Choose the smallest one (2) Put it on the top (3) Repeat (1) and (2) for the remaining numbers n 1 = 1 n 2 = n - 1 Why ? M ( n ) = n - 1 T ( n ) = T (1) + T ( n - 1) + ( n - 1) T (1) = 0
Background image of page 6
7 n n-1 n-2 n-3 2 2 ) 1 ( ) ( 0 ) 1 ( 1 ) 2 ( ... ... 4 ) 3 ( 3 ) 2 ( 2 ) 1 ( 1 ) ( 1 1 n n i M M M n n M n n M n n M n n M d i - - - - - - - - + = 1 1 1 1 1 1 T( n ) = T( n -1) + T(1) + M ( n ) n -1 = M ( n ) n -2 = M ( n -1) n -3 = M ( n -2) n -4 = M ( n -3) 1 = M ( 2 ) 0 = M ( 1 ) T(1) = 0 T(1) = 0 T(1) = 0 T(1) = 0 T(1) = 0 T(1) = 0 0 n -1
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 (1) Divide P into P 1 and P 2 of equal size (2) Solve P 1 and P 2 by recursively applying (1) T ( n ) = T ( n 1 )+ T ( n 2 )+ M ( n ) n n M n n n = = = ) ( 2 2 1 1 ) 1 ( ) 2 ( 2 ) ( = + = T n n T n T Why ? n n n n n n d = = = 1 2 ... ) 4 ( 4 ) 2 ( 2 n n/2 n/4 n/2 n/4 n/4 n/4 ……………………………………. 1 1 1 ………………. d n d n d 2 log , 2 : Note = = = = = d i i i n M n n n d 0 2 ) 2 / ( 2 log Merge Sort
Background image of page 8
9 (1) “Balance Competing Costs” Sorting Problem T ( n ) = T ( n 1 ) + … + T ( n k ) + M ( n ) k = # of subproblems d = depth k : smaller better, why? d : lower better, why? However, k d (Assuming that n 1 = n 2 = … = n k ) (2) “Balancing the sizes of subproblems” Balancing Strategy
Background image of page 9

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

View Full DocumentRight Arrow Icon
10 T(n-1) “Tower of Hanoi” Example T(n) T(n-1) 1
Background image of page 10
11 T ( n ) = 2 T ( n -1) + 1 T (1) = 1 Basic Operation ? Example
Background image of page 11

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

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

This note was uploaded on 02/04/2010 for the course COMPUTER S cs300 taught by Professor Unkown during the Spring '08 term at Korea Advanced Institute of Science and Technology.

Page1 / 38

CS300-04_Algorithm_Design - Algorithm Design Sung Yong Shin...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online