Recursion and Proofs by Induction CS1200, CSE IIT Madras Meghana - - PowerPoint PPT Presentation

recursion and proofs by induction
SMART_READER_LITE
LIVE PREVIEW

Recursion and Proofs by Induction CS1200, CSE IIT Madras Meghana - - PowerPoint PPT Presentation

Recursion and Proofs by Induction CS1200, CSE IIT Madras Meghana Nasre March 20, 2020 CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction Recursion Familiar recursive functions Some important recursive functions


slide-1
SLIDE 1

Recursion and Proofs by Induction

CS1200, CSE IIT Madras Meghana Nasre March 20, 2020

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-2
SLIDE 2

Recursion

Drawing Hands by M. C. Escher

  • Familiar recursive functions
  • Some important recursive functions
  • Proving closed form solutions using

induction

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-3
SLIDE 3

Some familiar examples

Factorial Function fact(n) = 1 if n = 1 = n · fact(n − 1)

  • therwise

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-4
SLIDE 4

Some familiar examples

Factorial Function fact(n) = 1 if n = 1 = n · fact(n − 1)

  • therwise

Fibonacci Sequence 0, 1, 1, 2, 3, 5, 8, . . . f (n) = n if n = 0 or n = 1 = f (n − 1) + f (n − 2)

  • therwise

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-5
SLIDE 5

Some more examples of recursive functions

gcd(a, b) : assume a ≥ b gcd(a, b) = a if b = 0 = gcd(b, a mod b)

  • therwise

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-6
SLIDE 6

Some more examples of recursive functions

gcd(a, b) : assume a ≥ b gcd(a, b) = a if b = 0 = gcd(b, a mod b)

  • therwise

n

i=0 i n

  • i=0

i = if n = 0 = n +

n−1

  • i=0

i

  • therwise

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-7
SLIDE 7

Proving bounds on recursive formulas using induction

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-8
SLIDE 8

An upper bound on f (n)

Claim: The n-th fibonacci number f (n) < 2n.

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-9
SLIDE 9

An upper bound on f (n)

Claim: The n-th fibonacci number f (n) < 2n. Base Case: n = 0, n = 1

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-10
SLIDE 10

An upper bound on f (n)

Claim: The n-th fibonacci number f (n) < 2n. Base Case: n = 0, n = 1 verify Ind Hyp: Assume that the claim holds for i = 0, . . . , k.

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-11
SLIDE 11

An upper bound on f (n)

Claim: The n-th fibonacci number f (n) < 2n. Base Case: n = 0, n = 1 verify Ind Hyp: Assume that the claim holds for i = 0, . . . , k. f (n) = f (n − 1) + f (n − 2)

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-12
SLIDE 12

An upper bound on f (n)

Claim: The n-th fibonacci number f (n) < 2n. Base Case: n = 0, n = 1 verify Ind Hyp: Assume that the claim holds for i = 0, . . . , k. f (n) = f (n − 1) + f (n − 2) < 2n−1 + 2n−2 by strong induction

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-13
SLIDE 13

An upper bound on f (n)

Claim: The n-th fibonacci number f (n) < 2n. Base Case: n = 0, n = 1 verify Ind Hyp: Assume that the claim holds for i = 0, . . . , k. f (n) = f (n − 1) + f (n − 2) < 2n−1 + 2n−2 by strong induction < 2n−1 + 2n−1 = 2 · 2n−1 = 2n.

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-14
SLIDE 14

An upper bound on f (n)

Claim: The n-th fibonacci number f (n) < 2n. Base Case: n = 0, n = 1 verify Ind Hyp: Assume that the claim holds for i = 0, . . . , k. f (n) = f (n − 1) + f (n − 2) < 2n−1 + 2n−2 by strong induction < 2n−1 + 2n−1 = 2 · 2n−1 = 2n. Tighter Bounds

  • f (n) ≤ 2n−1

for all n ≥ 1

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-15
SLIDE 15

An upper bound on f (n)

Claim: The n-th fibonacci number f (n) < 2n. Base Case: n = 0, n = 1 verify Ind Hyp: Assume that the claim holds for i = 0, . . . , k. f (n) = f (n − 1) + f (n − 2) < 2n−1 + 2n−2 by strong induction < 2n−1 + 2n−1 = 2 · 2n−1 = 2n. Tighter Bounds

  • f (n) ≤ 2n−1

for all n ≥ 1

  • f (n) ≤ φn−1

for all n ≥ 1; φ = 1+

√ 5 2

≈ 1.618 Does the same technique as above suffice to prove the second bound?

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-16
SLIDE 16

Another upper bound on f (n)

Claim: The n-th fibonacci number f (n) ≤ φn−1 for n ≥ 2.

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-17
SLIDE 17

Another upper bound on f (n)

Claim: The n-th fibonacci number f (n) ≤ φn−1 for n ≥ 2. Base Case: n = 2, n = 3 f (2) = 1 ≤ φ1 ≈ 1.618 f (3) = 2 ≤ φ2 ≈ 2.618 Ind Hyp: Assume that the claim holds for i = 2, . . . , k.

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-18
SLIDE 18

Another upper bound on f (n)

Claim: The n-th fibonacci number f (n) ≤ φn−1 for n ≥ 2. Base Case: n = 2, n = 3 f (2) = 1 ≤ φ1 ≈ 1.618 f (3) = 2 ≤ φ2 ≈ 2.618 Ind Hyp: Assume that the claim holds for i = 2, . . . , k. f (n) = f (n − 1) + f (n − 2)

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-19
SLIDE 19

Another upper bound on f (n)

Claim: The n-th fibonacci number f (n) ≤ φn−1 for n ≥ 2. Base Case: n = 2, n = 3 f (2) = 1 ≤ φ1 ≈ 1.618 f (3) = 2 ≤ φ2 ≈ 2.618 Ind Hyp: Assume that the claim holds for i = 2, . . . , k. f (n) = f (n − 1) + f (n − 2) ≤ φn−1 + φn−2 by strong induction

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-20
SLIDE 20

Another upper bound on f (n)

Claim: The n-th fibonacci number f (n) ≤ φn−1 for n ≥ 2. Base Case: n = 2, n = 3 f (2) = 1 ≤ φ1 ≈ 1.618 f (3) = 2 ≤ φ2 ≈ 2.618 Ind Hyp: Assume that the claim holds for i = 2, . . . , k. f (n) = f (n − 1) + f (n − 2) ≤ φn−1 + φn−2 by strong induction ≤ 2 · φn−1 similar to above proof

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-21
SLIDE 21

Another upper bound on f (n)

Claim: The n-th fibonacci number f (n) ≤ φn−1 for n ≥ 2. Base Case: n = 2, n = 3 f (2) = 1 ≤ φ1 ≈ 1.618 f (3) = 2 ≤ φ2 ≈ 2.618 Ind Hyp: Assume that the claim holds for i = 2, . . . , k. f (n) = f (n − 1) + f (n − 2) ≤ φn−1 + φn−2 by strong induction ≤ 2 · φn−1 similar to above proof !! However the above does not help to prove the claim. Hence we use some properties of φ.

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-22
SLIDE 22

Another upper bound on f (n)

Claim: The n-th fibonacci number f (n) ≤ φn−1 for n ≥ 2. Ind Hyp: Assume that the claim holds for all values i = 2, . . . k. f (n) = f (n − 1) + f (n − 2) ≤ φn−2 + φn−3 by strong induction

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-23
SLIDE 23

Another upper bound on f (n)

Claim: The n-th fibonacci number f (n) ≤ φn−1 for n ≥ 2. Ind Hyp: Assume that the claim holds for all values i = 2, . . . k. f (n) = f (n − 1) + f (n − 2) ≤ φn−2 + φn−3 by strong induction Note that φ (golden ratio) is a root of the equality x2 − x − 1 = 0 Thus we have φ + 1 = φ2.

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-24
SLIDE 24

Another upper bound on f (n)

Claim: The n-th fibonacci number f (n) ≤ φn−1 for n ≥ 2. Ind Hyp: Assume that the claim holds for all values i = 2, . . . k. f (n) = f (n − 1) + f (n − 2) ≤ φn−2 + φn−3 by strong induction ≤ φn−3(φ + 1) = φn−3 · φ2 = φn−1 Note that φ (golden ratio) is a root of the equality x2 − x − 1 = 0 Thus we have φ + 1 = φ2.

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-25
SLIDE 25

Another upper bound on f (n)

Claim: The n-th fibonacci number f (n) ≤ φn−1 for n ≥ 2. Ind Hyp: Assume that the claim holds for all values i = 2, . . . k. f (n) = f (n − 1) + f (n − 2) ≤ φn−2 + φn−3 by strong induction ≤ φn−3(φ + 1) = φn−3 · φ2 = φn−1 Hence proved! Note that φ (golden ratio) is a root of the equality x2 − x − 1 = 0 Thus we have φ + 1 = φ2.

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-26
SLIDE 26

A lower bound on f (n)

Claim: The n-th fibonacci number f (n) ≥ φn−2 for n ≥ 2. Ex: complete the proof. Ex: Read here about the Golden Ratio φ.

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-27
SLIDE 27

Recursively defined functions

A recursively defined function for non-negative integers as its domain:

  • Basis step: Define the function for first k positive integers.
  • Recursive step: Define the function for i > k using function value at

smaller integers.

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-28
SLIDE 28

Recursively defined functions

A recursively defined function for non-negative integers as its domain:

  • Basis step: Define the function for first k positive integers.
  • Recursive step: Define the function for i > k using function value at

smaller integers. Recursive functions are well-defined. That is, value of the function at any integer is determined unambiguously.

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-29
SLIDE 29

Recursively defined functions

A recursively defined function for non-negative integers as its domain:

  • Basis step: Define the function for first k positive integers.
  • Recursive step: Define the function for i > k using function value at

smaller integers. Recursive functions are well-defined. That is, value of the function at any integer is determined unambiguously. Ex: For the functions below, determine if they are well-defined and if yes, find a (non-recursive) formula for them and prove your formula using induction.

  • h(0) = 0; h(n) = 2h(n − 2)

for n ≥ 1.

  • g(0) = 0; g(n) = g(n − 1) − 1

for n ≥ 1.

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-30
SLIDE 30

Some important recursive functions

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-31
SLIDE 31

A fast growing function: Ackermann function

A(m, n) = 2n if m = 0 = if m ≥ 1 and n = 0 = 2 if m ≥ 1 and n = 1 = A(m − 1, A(m, n − 1)) if m ≥ 1 and n ≥ 2

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-32
SLIDE 32

A fast growing function: Ackermann function

A(m, n) = 2n if m = 0 = if m ≥ 1 and n = 0 = 2 if m ≥ 1 and n = 1 = A(m − 1, A(m, n − 1)) if m ≥ 1 and n ≥ 2 Ex: Solve the following.

  • Compute A(1, 1) and A(2, 2).
  • Guess a value for A(1, n) for n ≥ 1 and prove your answer using induction
  • n n.

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-33
SLIDE 33

A fast growing function: Ackermann function

A(m, n) = 2n if m = 0 = if m ≥ 1 and n = 0 = 2 if m ≥ 1 and n = 1 = A(m − 1, A(m, n − 1)) if m ≥ 1 and n ≥ 2 Ex: Solve the following.

  • Compute A(1, 1) and A(2, 2).
  • Guess a value for A(1, n) for n ≥ 1 and prove your answer using induction
  • n n.
  • Can you compute A(2, 3)?

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-34
SLIDE 34

A slow growing function: iterated logarithm

log(k)(n) = n if k = 0 = log(log(k−1)(n)) if log(k−1)(n) is defined and is positive = undefined

  • therwise

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-35
SLIDE 35

A slow growing function: iterated logarithm

log(k)(n) = n if k = 0 = log(log(k−1)(n)) if log(k−1)(n) is defined and is positive = undefined

  • therwise

Note: log(k)(n) is NOT log(n) · log(n) . . . log(n), k times. Assume base of logarithm is 2.

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-36
SLIDE 36

A slow growing function: iterated logarithm

log(k)(n) = n if k = 0 = log(log(k−1)(n)) if log(k−1)(n) is defined and is positive = undefined

  • therwise

Note: log(k)(n) is NOT log(n) · log(n) . . . log(n), k times. Assume base of logarithm is 2. Examples:

  • log(2)(16) = 2 whereas log2(16) = log(16) · log(16) = 4 · 4 = 16.
  • log(2)(200) < log(2)(256) = 3

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-37
SLIDE 37

A slow growing function: iterated logarithm

log(k)(n) = n if k = 0 = log(log(k−1)(n)) if log(k−1)(n) is defined and is positive = undefined

  • therwise

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-38
SLIDE 38

A slow growing function: iterated logarithm

log(k)(n) = n if k = 0 = log(log(k−1)(n)) if log(k−1)(n) is defined and is positive = undefined

  • therwise

Note: log(k)(n) is NOT log(n) · log(n) . . . log(n), k times. Assume base of logarithm is 2.

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-39
SLIDE 39

A slow growing function: iterated logarithm

log(k)(n) = n if k = 0 = log(log(k−1)(n)) if log(k−1)(n) is defined and is positive = undefined

  • therwise

Note: log(k)(n) is NOT log(n) · log(n) . . . log(n), k times. Assume base of logarithm is 2. Iterated Logarithm: log∗(n) : This is the smallest non-negative integer k such that log(k)(n) ≤ 1.

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-40
SLIDE 40

A slow growing function: iterated logarithm

log(k)(n) = n if k = 0 = log(log(k−1)(n)) if log(k−1)(n) is defined and is positive = undefined

  • therwise

Note: log(k)(n) is NOT log(n) · log(n) . . . log(n), k times. Assume base of logarithm is 2. Iterated Logarithm: log∗(n) : This is the smallest non-negative integer k such that log(k)(n) ≤ 1. Ex: What is log∗(4) and what is log∗(22048)?

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-41
SLIDE 41

A slow growing function: iterated logarithm

log(k)(n) = n if k = 0 = log(log(k−1)(n)) if log(k−1)(n) is defined and is positive = undefined

  • therwise

Note: log(k)(n) is NOT log(n) · log(n) . . . log(n), k times. Assume base of logarithm is 2. Iterated Logarithm: log∗(n) : This is the smallest non-negative integer k such that log(k)(n) ≤ 1. Ex: What is log∗(4) and what is log∗(22048)? Justify the title of the slide: slow growing function!

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction

slide-42
SLIDE 42

Summary

  • Some well-known and not so well-known recursive functions.
  • Use of induction to prove formulas.
  • Reference: Section 5.3 [KT].

To iterate is human, to recurse is divine.

  • L. Peter Deutsch

CS1200, CSE IIT Madras Meghana Nasre Recursion and Proofs by Induction