CSE 20 Lecture 12: Analysis of Homogeneous Linear Recursion
-
Upload
alana-huff -
Category
Documents
-
view
17 -
download
1
description
Transcript of CSE 20 Lecture 12: Analysis of Homogeneous Linear Recursion
1
CSE 20 Lecture 12: Analysis of Homogeneous Linear Recursion
CK ChengMay 5, 2011
2
3. Analysis
• 3.1 Introduction • 3.2 Homogeneous Linear Recursion• 3.3 Pigeonhole Principle• 3.4 Inclusion-Exclusion Principle
3
3.1 Introduction Derive the bound of functions or recursions Estimate CPU time and memory allocationEg. PageRank calculation
Allocation of memory, CPU time,Resource optimization
MRI imagingReal time?
VLSI designDesign automation flow to meet the deadline for tape out?
Further StudyAlgorithm, Complexity
4
3.1 Introduction • Derive the bound of functions or recursions • Estimate CPU time and memory allocation• Example on Fibonacci Sequence: Estimate fn.
– Index: 0 1 2 3 4 5 6 7 8 9 – fn: 0 1 1 2 3 4 5 8 13 21 34
1 1 5 1 1 5( ) ( )2 25 5
n nnf
0 00
1 1 5 1 1 5( ) ( ) 02 25 5
f
1
1 1 5 1 1 5( ) ( ) 12 25 5
f
5
Example: Fibonacci Sequence0 1 2 3 4 5 6 7 8 9
0 1 1 2 3 5 8 13 21 34
1 1 5 1 1 5( ) ( )2 25 5
1(1.618 0.618 )
2.2361
1.6182.236
n nn
n n
n
f
9
9
11.618 33.98
2.236f
6
3.2 Homogeneous Linear Recursion
• (1) Arithmetic Recursiona, a+d, a+2d, …, a+kd
• (2) Geometric Recursiona, ar, ar2, …, ark
• (3) Linear Recursionan= e1an-1+e2an-2+…+ekan-k+ f(n)
7
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.
8
Solving Linear Recursion
Input: Formulaand k initial values(1) characteristic
polynomial:(2)Find the root of the
characteristic polynomial (assuming ri are distinct)
(3)Set(4)Determine ci from k initial values
1 1 2 2 ...n n n k n ka e a e a e a 0 1 1, ,..., ka a a
1 21 2 ...k k k
kx e x e x e
1 2( , ,..., )kr r r
1 1 2 2 ...n n nn k ka c r c r c r
9
Solving Linear Recursion
Input: Formulaand k initial values(1) characteristic
polynomial:Rewrite the formula with
n=kReplace ai with xi
1 1 2 2 ...n n n k n ka e a e a e a 0 1 1, ,..., ka a a
1 21 2 ...k k k
kx e x e x e
1 1 2 2 0...k k k ka e a e a e a
10
Solving Linear Recursion
Input: Formulaand k initial values2. Find the root of the
polynomialOr,
1 1 2 2 ...n n n k n ka e a e a e a 0 1 1, ,..., ka a a
1 21 2 ...k k k
kx e x e x e
1 2( , ,..., )kr r r
1 21 2 ... 0k k k
kx e x e x e
11
Solving Linear Recursion
Input: Formulaand k initial values3. Set (assuming that the
roots are distinct.)
4. Determine ci from k initial values
1 1 2 2 ...n n n k n ka e a e a e a 0 1 1, ,..., ka a a
1 1 2 2 ...n n nn k ka c r c r c r
0 1 2 ... ka c c c
1 1 1 2 2 ... k ka c r c r c r
1 1 11 1 1 2 2 ...k k k
k k ka c r c r c r
... ...
12
Solving Linear Recursion
Input: Formulaand k initial values3. Set (when the roots are
not distinct.)
1 1 2 2 ...n n n k n ka e a e a e a 0 1 1, ,..., ka a a
1
( )u
n i ii
a g r
1
1
( )iw
j ni i ij i
j
g r c n r
1 2( , ,..., )ur r r
where ri is a root of multiplicity wi
13
Example on Fibonacci sequence
Input: initial values a0=0 and a1=1; and recursion formula an=an-1+an-2.
Rewrite recursion: an-an-1-an-2=0.
1. Characteristic polynomial: x2-x-1=0.2. Roots of the polynomial:
1
1 5,
2r
2
1 5
2r
3. Set: an=c1r1n+c2r2
n.
14
Example on Fibonacci sequenceInput: initial values a0=0 and a1=1; and recursion
formula an=an-1+an-2.
4. Determine ci from k initial valuesa0=c1r1
0+c2r20: c1+c2=0
a1=c1r11+c2r2
1:c1r1+c2r2=1, where
1
1 5,
2r
2
1 5
2r
Thus, we have1 2
1 1,5 5
c c
15
Example 2Given initial values a0=1 and a1=1;
and recursion formula: an=an-1+2an-2
Rewrite recursion: an-an-1-2an-2=0
1. Characteristic polynomial: x2-x-2=02. Characteristic roots: r1=2 and r2= -1
3. We have an=c1r1n+c2r2
n=c12n+c2(-1)n
4. We use two initial values for n=0 and n=1: a0=c1+c2
a1=c12+c2(-1)
16
Example 2 (cont)
Two initial valuesa0=c1+c2: c1+c2=1
a1=2c1+(-1)c2: 2c1-c2=1
Thus, we havec1=2/3, c2=1/3.
Since an=c1r1n+c2r2
n,
the formula is an=2/3*2n+1/3*(-1)n,
17
Example 3 (identical roots)Given initial values a0=1 and a1=1; and recursion
an=-2an-1-an-2
Rewrite the recursion: an+2an-1+an-2=0
1.Characteristic polynomial: x2+2x+1=02.Characteristic roots: r1=r2=-1
3.Formula for roots of multiplicity 2an=c1r1
n+c2nr1n=c1(-1)n+c2n(-1)n
Note the formula is different for roots of multiplicity.
18
Example 3 (identical roots)
Given initial values a0=1 and a1=1; and recursion an=-2an-1-an-2
4. Two initial conditions:a0=c1(-1)0+c20(-1)0=c1
a1=c1(-1)1+c21(-1)1=-c1-c2 with a0=1 and a1=1
Thus, c1= 1 and c2= -2.
Therefore, an= (-1)n-2n(-1)n
Exercise: verify the sequence a2, a3 and a4.