Professional Documents
Culture Documents
6 Induction and Recursion
6 Induction and Recursion
(L6)
Induction and
Recursion
Sequences
:Definition
A sequence {ai} is a function f: N {0} R, where we write ai
.to indicate f(i)
:Examples
a i a1 a2 ak
i1
ca i bi c ai bi
i1 i1 i1
(2k 1) 2 k 1
k1 k1 k1
…Summations you should know
?What is S = 1 + 3 + 5 + …Sum
+ (2nof
- 1)first n odds.
n2
r k
1 r r n
k 0 Multiply by r
n
r k
r r k
1 r n 1
k 0 k 0 factor
n n
n 1
(1 r) r 1 r
k n 1
divide r k 1 r
(1 r) DONE!
k 0 k 0
Mathematical Induction
One rule: Due to peer pressure, if the person
“before” you likes Yucky Charms, then you like
.Yucky Charms
Person 1 likes Yucky Charms.
- Spring 2004
What can we conclude? Everyone likes Yucky Charms!
Suggests a proof technique
- Spring 2004
If person k likes Fruit Loops, then
person k+1 does too. (FL(k) FL(k+1))
- Spring 2004
Mathematical Induction
Use induction to prove that the sum of the first n
Prove .aodd integers
base is n2
case (n=1)
Prove P(k)P(k+1)
- Spring 2004
is 12. Yup, 1 = 12.
Assume P(k): the sum of the first k odd ints is k2. 1 Inductive
hypothesis
+ 3 + … + (2k - 1) = k 2
- Spring 2004
Assume P(k): 11! + 22! + … + kk! = (k+1)! - 1 hypothesis
Deficient Tiling
A 2n x 2n sized grid is deficient if all but one
.cell is tiled
n
2
- Spring 2004
2n
Mathematical Induction - a cool
example
- Spring 2004
Mathematical Induction - a cool
example
- Spring 2004
Is it true for 21 x 21 grids?
Yup!
Mathematical Induction - a cool
example
:Inductive Hypothesis
We can tile a 2k x 2k deficient board using our
.fancy designer tiles
- Spring 2004
:Use this to prove
We can tile a 2k+1 x 2k+1 deficient board using our
.fancy designer tiles
Mathematical Induction - a cool
example 2k 2k
2k
? ?
- Spring 2004
2k+1
?
OK!!
2k (by
IH)
Mathematical Induction - a cool
example 2k 2k
OK!! OK!!
2k (by (by
- Spring 2004
IH) IH)
2k+1
OK!! OK!!
2k (by (by
IH) IH)
Mathematical Induction - a cool
example
- Spring 2004
Mathematical Induction - a cool
example
- Spring 2004
Homework
Recursive functions
Sometimes it is difficult to define an object explicitly. However, it •
may be easy to define this object in terms of itself. This process is
called recursion. For instance, the picture shown is produced
recursively
- Spring 2004
Recursively Defined Functions
:Example
f(0) = 3
11/19/21
f(n + 1) = 2f(n) + 3
- Spring 2004
Example: Factorial Function
Recursive Casen (n 1)!, if n 1 Inductive
n! (Recursive)
Base Case 1, if n 1 Definition
Recursive Functions - Factorial
11/19/21
f(0) = 1
f(n + 1) = (n + 1)f(n)
Fibonacci Numbers •
0 if n0
Base Cases
f (n) 1 if n 1
f (n 1) f (n 2) if n 1 Recursive Case
Is there a non-recursive
definition for the Fibonacci
Numbers?
28
Recursively Defined Functions
Fibonacci Numbers
f(0) = 0, f(1) = 1
f(n) = f(n – 1) + f(n - 2)
11/19/21
f(0) = 0
f(1) = 1
11/19/21
rabbits would be produced in perfect circumstances. (i.e.
11/19/21
Each female reproduces every month, starting from .2•
31
Recursively Defined Functions
Fibonacci Numbers
11/19/21
COCS 222 - Discrete Structures
32
Recursively Defined Sequences
:Example
11/19/21
:The same sequence can also be defined recursively
11/19/21
an = 6n