CH 9
CH 9
Recursion
9 21 45 93
Recursive definition of
Factorial
Give an inductive (recursive) definition of the factorial
function,
F(n) :≡ n! :≡ ∏1≤i≤n i = 12…n.
Base case: F(0) :≡ 1
Recursive part: F(n) :≡ n F(n−1).
F(1)=1
F(2)=2
F(3)=6
More Easy Examples
0
1 1
2 3
58
13
Leonardo Fibonacci
1170-1250
Inductive Proof about Fib.
series
Thm. fn < 2n. Implicitly for all nℕ
Proof. By induction.
Base cases: f0 = 0 < 20 = 1 Note use of
f1 = 1 < 2 = 2
1
base cases of
Inductive step: Use 2nd principle of induction (strong
induction). Assume k<n, fk < 2k. recursive def’n.
Then fn = fn−1 + fn−2 is
< 2n−1 + 2n−2 < 2n−1 + 2n−1 = 2n. ■
A lower bound on
Fibonacci series
Thm. For all integers n ≥ 3, fn > αn−2, where α
= (1+51/2)/2 ≈ 1.61803.
Proof. (Using strong induction.)
Let P(n) = (fn > αn−2).
Base cases:
For n=3, α3−2 = α ≈ 1.61803 < 2 = f3.
For n=4, α4−2 = α2 = (1+2·51/2+5)/4 = (3+51/2)/2 ≈
2.61803 < 3 = f4.
Inductive step:
For k≥4, assume P(j) for 3≤j≤k, prove P(k+1).
Note α2 = α+1. α(k+1)−2 = αk−1 = α2 αk−3 = (α+1)αk−3 =
αk−2 + αk−3. By inductive hypothesis, fk−1 > αk−3 and
fk > αk−2. So,
α(k+1)−2 = αk−2 + αk−3 < fk + fk−1 = fk+1. Thus P(k+1).
■
Lamé’s Theorem
T1
r1
T2
r2
… Tn
rn
mpower(b,n/2,m)) mod m
else return (mpower(b,n−1,m)·b)
mod m
The number of recursive calls made is critical!
Recursive Euclid’s Algorithm
procedure gcd(a,bN)
if a = 0
then return b
else return gcd(b mod a, a)