Algorithm Analysis Recurrence Relation Chung-Ang University, Jaesung Lee
Recursion 2
Recursion 3
Recursion in Real-world Fibonacci sequence = + Initial conditions: = 0 and = 1. = + = + = + 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89,... 4
Recursion in Real-world Towers of Hanoi 5
Recursion in Real-world Towers of Hanoi 6
Recursion in Real-world Towers of Hanoi 7
Recursion in Real-world Towers of Hanoi 8
Recursion in Real-world Towers of Hanoi 9
Recursion in Real-world Towers of Hanoi 10
Recursion in Real-world Towers of Hanoi 11
Recursion in Real-world Towers of Hanoi 12
Recursion in Real-world Towers of Hanoi 13
Recursion in Real-world Towers of Hanoi 14
Recursion in Real-world Towers of Hanoi 15
Recursion in Real-world Towers of Hanoi 16
Recursion in Real-world Towers of Hanoi 17
Recursion in Real-world Towers of Hanoi 18
Recursion in Real-world Towers of Hanoi 19
Recursion in Real-world Towers of Hanoi 20
Recursion in Real-world Towers of Hanoi 21
Recursion in Algorithms Binary search 22
Recursion in Algorithms Binary search 23
The Fibonacci sequence is the sequence of numbers F(0), F(1), \ldots defined by the following recurrence relations: for all > 1 (0) = 1, (1) = 1, ( ) = ( 1) + ( 2) By solving Recurrence equation of Fibonacci sequence, we get = 1 5 1 + 5 2 1 5 2 for all 1 24
Some guess and check with respect to solving recurrence relation are: Make simplifying assumptions about inputs Tabulate the first few values of the recurrence Look for patterns, guess a solution Generalize the result to remove the assumptions 25
The Iterative Substitution Methods Recursion Tree The Guess-and-Test Method 26
The Iterative Substitution Methods Merge sort recurrence equation: = 2 2 = 2 2 2 + 2 + + 2 27
The Iterative Substitution Methods Plugging the general equation for again yields the equation: = 2 2 2 + 2 + 2 = 2 2 + 3 28
The Iterative Substitution Methods General form of merge sort recurrence equation: = 2 2 + 29
The Recursion Tree 30
The Recursion Tree 31
The Recursion Tree 32
The Recursion Tree For example, consider the following recurrence equation: = < 3 3 + 3 33
The Recursion Tree 34
The Guess-and-Test Method 35
Example 1 Consider the following recurrence equation: = 2 + log Assuming the base case = for < 2. 36
Example 1 If we assume our first guess as an inductive hypothesis that is true for input sizes smaller than, then we have: ( ) = 2 2 + log 2 2 log + log 2 log log 2 + log log + log 37
Example 1 Consider the following recurrence equation: = 2 + log Assuming the base case = for < 2. log + log Let us try: Better guess: log for some constant > 0. 38
Example 1 Consider the following recurrence equation: = 2 + log, and assuming the base case = for < 2. provided. = 2 2 + log 2 2 log + log 2 log 2log + 1 + log log 2 log + + log log 39
Example 2 Consider the following recurrence equation: = 2 + log Assuming the base case = for < 2. Consider the following: First guess: for some constant > 0. 40
Example 2 Consider the following recurrence equation: = 2 + log Assuming the base case = for < 2. = 2 2 2 + log + log 2 + log 41
Example 2 Consider the following recurrence equation: = 2 + log Assuming the base case = for < 2. + log Using a better guess: ( ) ( log ) for some constant > 0. 42
Example 2 Consider the following recurrence equation: = 2 + log Assuming the base case = for < 2. provided 3 and 8. = 2 2 + log 2 2 log 2 + log 2 log + 2 + log log log + 2 + log log 43
Example 2 Consider the following recurrence equation: = 2 + log Assuming the base case = for < 2. Using a better guess: log provided 3 and 8. 44
The Master Theorem Method 45
The Master Theorem Method For recurrence equations of the form: = < + where > 1 is an integer constant, > 0, > 0, and > 1 are real constants, and is a function that is positive for. 46
The Master Theorem Case 1: is Θ If there is a small constant > 0, such that is 47
The Master Theorem Case 2 If there is a constant 0, such that is Θ log, then is Θ log. This case characterizes the situation when function. is asymptotically close to special 48
The Master Theorem Case 3 If there are small constant > 0 and < 1, such that is Ω and <, for, then is Θ. 49
Example 1 = 4 + In this case, = = so that it is the Case 1 for is for = 1. Thus = Θ by the master method. 50
Example 2 = 2 + log In this case, = =. Thus, we are in Case 2, with = 1, for is Θ log. This means that is Θ log by the master method. 51
Example 3 = + In this case, = = = 1. Thus, we are in Case 3, for is Ω, for = 1, and = =. This means that is Θ by the master method. 52
Example 4 Consider the recurrence = 9 +.. In this case, = =. Thus, we are in Case 3, since is Ω, for =, and = 9. This means that is Θ. by the master method.. = 53
Example 5 = 2. + log Not in a form of master method By introducing the variable = log ( = 2 ): = 2 = 2 2. + = 2 2. + 54
Example 5 By introducing the variable = log : = 2 = 2 2. + Substituting into = log and the equation = 2, we get that = 2 2 + = 2 0.5 = 2. 55
Example 5 = 2 + = log Substituting back for : = log log log 56
Example 5 = 2 + = log Substituting back for : = log log log 57