Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CSE 20 Lecture 13: Analysis of Recursive Functions CK Cheng.

Similar presentations


Presentation on theme: "1 CSE 20 Lecture 13: Analysis of Recursive Functions CK Cheng."— Presentation transcript:

1 1 CSE 20 Lecture 13: Analysis of Recursive Functions CK Cheng

2 2 3. Analysis 3.1 Introduction 3.2 Homogeneous Linear Recursion

3 3 3.1 Introduction Derive the bound of functions or recursions Estimate CPU time and memory allocation Eg. PageRank calculation Allocation of memory, CPU time, Resource optimization MRI imaging Real time? VLSI design Design automation flow to meet the deadline for tape out? Further Study Algorithm, Complexity

4 4 3.1 Introduction Derive the bound of functions or recursions Estimate CPU time and memory allocation Example on Fibonacci Sequence: Estimate f n. – Index: 0 1 2 3 4 5 6 7 8 9 – f n : 0 1 1 2 3 5 8 13 21 34

5 5 Example: Fibonacci Sequence 0123456789 0112358132134

6 6 Example: Fibonacci Sequence, iClicker Suppose g 0 =0 and g 1 =2, g n =g n-1 +g n-2 what is g n A. g n =f n B. g n =2f n C. g n =3f n D. None of the above

7 7 3.2 Homogeneous Linear Recursion (1) Arithmetic Recursion a, a+d, a+2d, …, a+kd (2) Geometric Recursion a, ar, ar 2, …, ar k (3) Linear Recursion a n = e 1 a n-1 +e 2 a n-2 +…+e k a n-k + f(n)

8 8 Linear Recursion and Homogeneous Linear Recursion Linear Recursion: There are no powers or products of Homogenous Linear Recursion: A linear recursion with f(n)=0.

9 9 Solving Linear Recursion Input: Formula and k initial values Output: a n as a function of n 1. Set characteristic polynomial: 2. Find the root of the characteristic polynomial (assuming r i are distinct) 3. Express 4. Determine c i from k initial values

10 10 Solving Linear Recursion Input: Formula and k initial values 1. Set characteristic polynomial: Rewrite the formula with n=k Replace a i with x i

11 11 Solving Linear Recursion Input: Formula and k initial values 2. Find the root of the polynomial Or,

12 12 Solving Linear Recursion Input: Formula and k initial values 3. Express (assuming that the roots are distinct.) 4. Determine c i from k initial values

13 13 Solving Linear Recursion Input: Formula and k initial values 3. Set (when the roots are not distinct.) where r i is a root of multiplicity w i

14 Example on Fibonacci sequence Input: initial values a 0 =0 and a 1 =1; and recursion formula a n =a n-1 +a n-2. Rewrite recursion: a n -a n-1 -a n-2 =0. Or a 2 -a 1 -a 0 =0. 1. Characteristic polynomial: x 2 -x-1=0. 2. Roots of the polynomial: 14 3. Set: a n =c 1 r 1 n +c 2 r 2 n.

15 Example on Fibonacci sequence Input: initial values a 0 =0 and a 1 =1; and recursion formula a n =a n-1 +a n-2. 4. Determine c i from k initial values a 0 =c 1 r 1 0 +c 2 r 2 0 => c 1 +c 2 =0 a 1 =c 1 r 1 1 +c 2 r 2 1 => c 1 r 1 +c 2 r 2 =1. 15 Thus, we have a n =c 1 r 1 n +c 2 r 2 n, where

16 16 Example 2

17 Example 2 (cont) Two initial values a 0 =c 1 +c 2 :c 1 +c 2 =1 a 1 =2c 1 +(-1)c 2 :2c 1 -c 2 =1 Thus, we have c 1 =2/3, c 2 =1/3. Since a n =c 1 r 1 n +c 2 r 2 n, we have a n =2/3×2 n +1/3×(-1) n, 17

18 18 Example 3


Download ppt "1 CSE 20 Lecture 13: Analysis of Recursive Functions CK Cheng."

Similar presentations


Ads by Google