Top Banner
INDUCTION AND RECURSION Lecture 7 - Ch. 4
16

INDUCTION AND RECURSION - WordPress.com · § Or, using recursion: 1. Find first term of the sequence, namely, a 0 = 1, then 2. find a term of the sequence from the previous one,

Apr 25, 2018

Download

Documents

buinhan
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: INDUCTION AND RECURSION - WordPress.com · § Or, using recursion: 1. Find first term of the sequence, namely, a 0 = 1, then 2. find a term of the sequence from the previous one,

INDUCTION AND RECURSION

Lecture 7 - Ch. 4

Page 2: INDUCTION AND RECURSION - WordPress.com · § Or, using recursion: 1. Find first term of the sequence, namely, a 0 = 1, then 2. find a term of the sequence from the previous one,

4. Introduction

¨ Any mathematical statements assert that a property is true for all positive integers

¨ Examples: for every positive integer n:¤ n! <= nn

¤ n3 -n is divisible by 3¤a set with n elements has 2n subsets¤ the sum of the first n positive integers is n(n + 1 )

This chapter goal is to understand the mathematical induction, and how it is used to prove results of this kind

2

Page 3: INDUCTION AND RECURSION - WordPress.com · § Or, using recursion: 1. Find first term of the sequence, namely, a 0 = 1, then 2. find a term of the sequence from the previous one,

4.1 Mathematical Induction

¨ Mathematical Induction is used to show that P(n) is true for every positive integer n.

¨ Example: Suppose we have an infinite ladder, and we want to know whether we can reach every step on the ladder. We know two things1. We can reach the first rung of the ladder.2. If we can reach a particular rung of the ladder, then we can reach the next rung.

3

Page 4: INDUCTION AND RECURSION - WordPress.com · § Or, using recursion: 1. Find first term of the sequence, namely, a 0 = 1, then 2. find a term of the sequence from the previous one,

4

4.1 Mathematical Induction

PRINCIPLE OF MATHEMATICAL INDUCTIONTo prove that P(n) is true for all positive integers n, where P(n) is apropositional function, we complete two steps. 1. BASIS STEP: We verify that P(1) is true.2. INDUCTIVE STEP: We show that the conditional statement P(k) →P(k+1) is true for all positive integers k. q The assumption that P(k) is true is called the inductive hypothesis. q To complete the inductive step of a proof using the principle of mathematical

induction, we assume that P(k) is true for an arbitrary positive integer k and show that under this assumption, P(k+1) must also be true.

The proof technique is stated as [P(1)Λ ∀k(P(k) →P(k+1) )] → ∀nP(n)where the domain is the set of positive integers

Page 5: INDUCTION AND RECURSION - WordPress.com · § Or, using recursion: 1. Find first term of the sequence, namely, a 0 = 1, then 2. find a term of the sequence from the previous one,

5

4.1 Mathematical Induction

Show that if n is a positive integer, thenSolution:BASIS STEP: because P(1)=1 (LHS), =1 (RHS). Thus, P(1) is trueINDUCTIVE STEP: a) Assume P(k) is true for an arbitrary positive integer k. That is, we assume that

P(k)=

b) Under assumption (a), it must be shown that P(k+1) is true, i.e.:

P(k+1)=

c) Comparing LHS in (a) and (b), we add k+1 to both sides of the equation in P(k)

P(k)+k+1= =P(k+1)

This shows that P(k+1) is true under the assumption that P(k) is true. 5

Example 1

2)1(...21 +

=+++nnn

2)11(1 +

2)1(...21 +

=+++kkk

2)2)(1(

2]1)1)[(1()1(...21 ++=

+++=+++++

kkkkkk

2)2)(1(

2)1(2)1()1(

2)1()1(...21 ++

=+++

=+++

=+++++kkkkkkkkkk

Page 6: INDUCTION AND RECURSION - WordPress.com · § Or, using recursion: 1. Find first term of the sequence, namely, a 0 = 1, then 2. find a term of the sequence from the previous one,

6

For all nonnegative integers n. Use mathematical induction to show that: 1 + 2 + 22

+· · ·+2n = 2n+1 − 1Solution:BASIS STEP: because P(1)= 20 = 1 (LHS), 21 − 1 =1 (RHS). Thus, P(1) is trueINDUCTIVE STEP: a) Assume P(k) is true for an arbitrary positive integer k. That is, we assume thatP(k)= 1 + 2 + 22 +· · ·+2k = 2k+1 − 1

b) Under assumption (a), it must be shown that P(k+1) is true, i.e.:

P(k+1)=1 + 2 + 22 +· · ·+2k + 2k+1 = 2(k+1)+1 − 1 = 2k+2 − 1

c) Comparing LHS in (a) and (b), we add 2k+1 to both sides of the equation in P(k)

P(k)+ 2k+1 = 1 + 2 + 22 +· · ·+2k + 2k+1 = (2k+1 − 1) + 2k+1

= 2 · 2k+1 − 1 = 2k+2 − 1 =P(k+1)This shows that P(k+1) is true under the assumption that P(k) is true.

Example 2:4.1 Mathematical Induction

Page 7: INDUCTION AND RECURSION - WordPress.com · § Or, using recursion: 1. Find first term of the sequence, namely, a 0 = 1, then 2. find a term of the sequence from the previous one,

7

4.2 Strong Induction

PRINCIPLE OF STRONG INDUCTIONTo prove that P(n) is true for all positive integers n, where P(n) is a propositional function, we complete two steps:1. BASIS STEP : We verify that the proposition P(1) is true.2. INDUCTIVE STEP: We show that the conditional statement [P(1) /\ P(2) /\ . . . /\ P(k)] à P(k + 1) is true for all positive integers k.

Note:When we use strong induction to prove that P (n) is true for all positive integers n , our inductive hypothesis is the assumption that P(j) is true for j = 1,2, ... , k. That is, the inductive hypothesis includes all k statements P(1), P(2), ... , P(k). Because we can use all k statements P(1), P(2), ... , P(k) to prove P(k + 1), rather than just the statement P(k) as in a proof by mathematical induction, strong induction is a more flexible proof technique.

Page 8: INDUCTION AND RECURSION - WordPress.com · § Or, using recursion: 1. Find first term of the sequence, namely, a 0 = 1, then 2. find a term of the sequence from the previous one,

8

Show that if n is an integer greater than 1 , then n can be written as the product of primes.Solution:BASIS STEP: because the first case is P(2)= 2 (prime#).Thus, P(2) is trueINDUCTIVE STEP: a) The inductive hypothesis is the assumption that P(j) is true for all positive

integers 2 ≤ j ≤ k

b) We show that P(k+1) is true under assumption (a), that is, we must show that k+1 is the product of primes. There are two cases to consider:

1. k+1 is prime à P (k+1) is true

2. k+1 is compositeà P (k+1)= a*b (2≤a≤b<k+1)

By the inductive hypothesis, both a and b can be written as the product of primes. Thus, if k + 1 is composite, it can be written as the product of primes, namely, those primes in the factorization of a and those in the factorization of b.

4.2 Strong InductionExample 1:

Page 9: INDUCTION AND RECURSION - WordPress.com · § Or, using recursion: 1. Find first term of the sequence, namely, a 0 = 1, then 2. find a term of the sequence from the previous one,

9

Use strong induction to show that if you can run one mile or two miles, and if you can always run two more miles once you have run a specified number of miles, then you can run any number of miles.

Solution:BASIS STEP: because we are told we can run one mile, so P (1) is true

INDUCTIVE STEP: a) The inductive hypothesis is the assumption that P(j) is true; which is we can run any number of

miles from 1 to k. [P(j) is true for all positive integers 1 ≤j ≤ k]

b) We show that P(k+1) is true under assumption (a), that is, we must show that we can run

k + 1 miles:

¨ If k = 1 , then we are already told that we can run two miles.

¨ If k > 1 , then the inductive hypothesis tells us that we can run k-1 miles, so we can run

(k-1) + 2 = k + 1 miles.

4.2 Strong InductionExample 2:

Page 10: INDUCTION AND RECURSION - WordPress.com · § Or, using recursion: 1. Find first term of the sequence, namely, a 0 = 1, then 2. find a term of the sequence from the previous one,

10Introduction

4.3 Recursive Definitions and Structural Induction

Page 11: INDUCTION AND RECURSION - WordPress.com · § Or, using recursion: 1. Find first term of the sequence, namely, a 0 = 1, then 2. find a term of the sequence from the previous one,

11

4.3 Recursive Definitions and Structural Induction

¨ Sometimes it’s easier to define an object in terms of itself. This process is called Recursion.

¨ Example: The sequence of powers of 2: 1, 2, 4, 8, 16, 32, 64, 128, …

can be found by:§ Using the sequence given by the formula an = 2n

for n = 0, 1, 2, …§ Or, using recursion:

1. Find first term of the sequence, namely, a0 = 1, then2. find a term of the sequence from the previous one, namely,

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

Page 12: INDUCTION AND RECURSION - WordPress.com · § Or, using recursion: 1. Find first term of the sequence, namely, a 0 = 1, then 2. find a term of the sequence from the previous one,

12

4.3 Recursive Definitions and Structural Induction

¨ Use two steps to define a function with the set of nonnegative integers as its domain:BASIS STEP: Specify that value of the function at zero. (f(0))RECURSIVE STEP: Give a rule for finding its value at an integer from its values at smaller integers. (f(n)=g(n-1))

¨ Such a definition is called a recursive or inductive definition.¨ Examples:

¤ Suppose that f is defined recursively byf(0) = 3,f(n) = 2f(n-1) + 3Find f(1), f(2), f(3), and f(4).

Solution:f(1) = 2f(0) + 3 = 2*3 + 3 = 9f(2) = 2f(1) + 3 = 2*9 + 3 = 21f(3) = 2f(2) + 3 = 2*21 + 3 = 45f(4) = 2f(3) + 3 = 2*45 + 3 = 93

Recursively Defined Functions

Page 13: INDUCTION AND RECURSION - WordPress.com · § Or, using recursion: 1. Find first term of the sequence, namely, a 0 = 1, then 2. find a term of the sequence from the previous one,

13

4.3 Recursive Definitions and Structural Induction

¨ Example1:¤ Give an recursive definition of the factorial function f(n) = n! . Then find f(5)

Solution:The recursive definition is:¤ Basis Step: f(0) = 1¤ Recursive Step: f(n) = (n)*f(n-1)

F(5) =5 F(4) =5*4F(3) =5*4*3 F(2)=5 * 4 * 3 * 2F(1)=5 * 4 * 3 * 2 * 1F(0)= 5 * 4 * 3 * 2 * 1 * 1= 120

Page 14: INDUCTION AND RECURSION - WordPress.com · § Or, using recursion: 1. Find first term of the sequence, namely, a 0 = 1, then 2. find a term of the sequence from the previous one,

14

4.3 Recursive Definitions and Structural Induction

¨ Example2:¤ Give a recursive definition of .

Solution:

= a0 + a1 + a2 + a3 + … an

Basis Step:

Inductive Step:

#𝑎% ='

%()

# 𝑎% + 𝑎'

'+,

%()

å=

n

kka

0

0

0

0

aak

k =å=

å=

n

kka

0

Page 15: INDUCTION AND RECURSION - WordPress.com · § Or, using recursion: 1. Find first term of the sequence, namely, a 0 = 1, then 2. find a term of the sequence from the previous one,

15

¨ Example: Find the Fibonacci numbers f2, f3, f4, f5, and f6. Solution:f2 = f1 + f0 = 1 + 0 = 1,f3 = f2 + f1 = 1 + 1 = 2,f4 = f3 + f2 = 2 + 1 = 3,f5 = f4 + f3 = 3 + 2 = 5, f6 = f5 + f4 + 5 + 3 = 8.

¨ Example: Find the Fibonacci numbers f7. Solution ?

DEFINITION 1The Fibonacci numbers, f0, f1, f2, …, are defined by the equations Basis step: f0= 0, f1 =1Recursive step: fn = fn-1 + fn-2

for n = 2, 3, 4, ….

4.3 Recursive Definitions and Structural Induction

Page 16: INDUCTION AND RECURSION - WordPress.com · § Or, using recursion: 1. Find first term of the sequence, namely, a 0 = 1, then 2. find a term of the sequence from the previous one,

16

f4

f3 f2

f2f1 f1 f0

f1 f0

fn+1 -1 addition to find fn

(f5 -1) addition to find f4= (5-1) = 4 additions

4.3 Recursive Definitions and Structural Induction