Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 35

Discrete Structures

(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

Cs173 - Spring 2004


… ,Sequence {ai}, where ai = i is just a0 = 0, a1 = 1, a2 = 2

… ,Sequence {ai}, where ai = i2 is just a0 = 0, a1 = 1, a2 = 4


Summation
The symbol
k

a i  a1  a2    ak

i1

?How do you know this is true

Cs173 - Spring 2004


k k k

  ca i  bi   c  ai   bi
i1 i1 i1

Use associativity to separate the bs from the as.

Use distributivity to factor the cs.



…Summations you should know
?What is S = 1 + 2 + 3 + … + n

S = 1 + 2 + … + n Write the sum.

Cs173 - Spring 2004


S = n + n-1 + … + 1 Write it again.

2s = n+1 + n+1 + … + n+1 Add together.

You get n copies of (n+1). But we’ve over added


by a factor of 2! So just divide by 2.
n
n(n  1)
k  2
k1
…Summations you should know
?What is S = 1 + 3 + 5 + …Sum
+ (2nof
- 1)first n odds.
n n n

 (2k  1)  2 k  1
k1 k1 k1

Cs173 - Spring 2004


n(n  1) 
 2  n
 2 

n 2



…Summations you should know
?What is S = 1 + 3 + 5 + …Sum
+ (2nof
- 1)first n odds.

 n2

Cs173 - Spring 2004



…Summations you should know
What is S = 1 + rGeometric
+ r2 + … + rSeries
n

 r k
 1  r    r n


k 0 Multiply by r
n

Cs173 - Spring 2004


r r k  r  r 2    r n 1
k 0 Subtract 2nd from 1st
 n 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

Spose we want to prove everyone likes Fruit Loops n FL(n)


Need to show two things:
Person 1 likes Fruit Loops (FL(1))
If person k likes Fruit Loops, then
person k+1 does too. (FL(k)  FL(k+1))
Mathematical Induction
Spose we want to prove everyone likes Fruit Loops n FL(n)
Need to show two things:
Person 1 likes Fruit Loops (FL(1))

- Spring 2004
If person k likes Fruit Loops, then
person k+1 does too. (FL(k)  FL(k+1))

First part is a simple proposition we call the base


case.
Second part is a conditional. Start by assuming
FL(k), and show that FL(k+1) follows.
True by “peer
pressure”
Examples

- 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)

Base case (n=1): the sum of the first 1 odd integer

- 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

Prove that 1 + 3 + … + (2k - 1) + (2k + 1) = (k+1)2


By inductive
1 + 3 + … + (2k-1) + (2k+1) = k2 + (2k + 1) hypothesis
= (k+1)2
By arithmetic
Mathematical Induction
Prove that 11! + 22! + … + nn! = (n+1)! - 1, n

Base case (n=1): 11! = (1+1)! - 1?


Yup, 11! = 1, 2! - 1 = 1
Inductive

- Spring 2004
Assume P(k): 11! + 22! + … + kk! = (k+1)! - 1 hypothesis

Prove that 11! + … + kk! + (k+1)(k+1)! = (k+2)! - 1


11! + … + kk! + (k+1)(k+1)! = (k+1)! - 1 + (k+1)(k+1)!
= (1 + (k+1))(k+1)! - 1
= (k+2)(k+1)! - 1
= (k+2)! - 1
Mathematical Induction
Mathematical Induction
This part is not important, it is just for clarification of induction

Mathematical Induction - a cool


example

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

We want to show that all 2n x 2n sized


deficient grids can be tiled with tiles
shaped like:

- Spring 2004
Mathematical Induction - a cool
example

?Is it true for 20 x 20 grids


Yup!

- 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

COCS 222 - Discrete Structures


f(0) = 3
f(1) = 2f(0) + 3 = 23 + 3 = 9
f(2) = 2f(1) + 3 = 29 + 3 = 21
f(3) = 2f(2) + 3 = 221 + 3 = 45
f(4) = 2f(3) + 3 = 245 + 3 = 93 25
Recursive functions -
Factorial

- Spring 2004
Example: Factorial Function
Recursive Casen  (n  1)!, if n  1 Inductive
n!  (Recursive)
Base Case 1, if n  1 Definition
Recursive Functions - Factorial

Another way to represent factorial function f(n) = n!


recursively

11/19/21
f(0) = 1
f(n + 1) = (n + 1)f(n)

COCS 222 - Discrete Structures


f(0) = 1
f(1) = 1f(0) = 11 = 1
f(2) = 2f(1) = 21 = 2
f(3) = 3f(2) = 32 = 6
f(4) = 4f(3) = 46 = 24 27
Recursive Functions –
Fibonacci Numbers
:The 2nd most commonNote why you
example • need
two base cases.

Fibonacci Numbers •
0 if n0
 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

COCS 222 - Discrete Structures


f(2) = f(1) + f(0) = 1 + 0 = 1
f(3) = f(2) + f(1) = 1 + 1 = 2
f(4) = f(3) + f(2) = 2 + 1 = 3
f(5) = f(4) + f(3) = 3 + 2 = 5
f(6) = f(5) + f(4) = 5 + 3 = 8
29
Recursively Defined Functions
Fibonacci Numbers
In 1202, Italian mathematician Fibonacci posed a•
mathematical rabbit problem.  In his book Liber Abaci
(The Book of Calculations) he wondered how many

11/19/21
rabbits would be produced in perfect circumstances. (i.e.

COCS 222 - Discrete Structures


where there are no predators, just like on Rabbit Island!)
:Fibonacci posed the theoretical problem as follows•
Imagine you have a pair of rabbits, one male and one•
female in a field.  How many rabbits will they produce
?after one year
30
Recursively Defined Functions
Fibonacci Numbers
:Fibonacci made the following assumptions•

No rabbits die or are eaten by predators .1•

11/19/21
Each female reproduces every month, starting from .2•

COCS 222 - Discrete Structures


.the second month that she is alive
Every time the female reproduces she gives birth to .3•
.one pair of rabbits – (one male and one female)

31
Recursively Defined Functions
Fibonacci Numbers

11/19/21
COCS 222 - Discrete Structures
32
Recursively Defined Sequences
:Example

The sequence {an} of powers of 2 is given by


. … ,an = 2n for n = 0, 1, 2

11/19/21
:The same sequence can also be defined recursively

COCS 222 - Discrete Structures


a0 = 1
… ,an+1 = 2an for n = 0, 1, 2

Obviously, induction and recursion are similar


.principles
33
Recursively Defined Sequences
:Example

Give a recursive definition of the sequence {an},•


n=1,2,3… if

11/19/21
an = 6n

COCS 222 - Discrete Structures


; Basic Step a0=0•
Recursive Step:•
an+1 = 6(n+1)
=6n + 6
= an + 6 34
Exercises

COCS 222 - Discrete Structures 11/19/21


35

You might also like