Top Banner
Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar
38

Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Dec 23, 2015

Download

Documents

Arlene Hawkins
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 by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Induction and Recursion

by:

Mohsin tahir (GL)

Numan-ul-haq

Waqas akram

Rao arslan

Ali asghar

Page 2: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Contents

Mathematical Inductions Strong Induction Recursion

Page 3: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

MathematicalInduction

Page 4: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Suppose we have an infinite ladder: • We can reach the first rung of the

ladder.• If we can reach a particular rung of

the ladder, then we can reach the next rung.

From (1), we can reach the first rung. Then by applying (2), we can reach the second rung. Applying (2) again, the third rung. And so on. We can apply (2) any number of times to reach any particular rung, no matter how high up.

This example motivates proof by mathematical induction.

Climbing an Infinite Ladder

Ladder

Page 5: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

MathematicalInduction Mathematical induction is an extremely important

proof technique.

It is extremely important to note that mathematical induction can be used only to prove results obtained.

It is not a tool for discovering formulae or theorems.

Page 6: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Let P(n) be a propositional (formula),satisfies that following condition,

Step#1: for n=1

p(1) is true. “Case 1 is satisfied”

Step#2: The result (formula) is true for n=k

(where k is integer +ive)

p(k) is true. “case 2 is satisfied”

Step#3: now we have to show that, the result is true for

n=k+1 , if p(k+1) is true then proposition p(n) is true for all positive integer value of n.

Definition:-

Page 7: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

PRINCIPLE OF MATHEMATICAL INDUCTION

To prove that P(n) is true for all positive integers n, where P(n) is a propositional function, we complete two steps: BASIS STEP: The proposition P(1) is true. INDUCTIVE STEP: The proposition p(k) is true for

n=k also p(k+1) is show to be true for n=k+1,

hence both P(k) → P(k + 1) is true for all positive integers k.

To complete the inductive step, assuming the inductive hypothesis that P(k) holds for an arbitrary integer k, show that must P(k + 1) be true.

Page 8: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Climbing an Infinite Ladder Example:

Basis Step: By (1), we can reach rung 1.

Inductive Step: Assume the inductive hypothesis that we can reach rung k. Then by (2), we can reach rung k + 1.

Hence, P(k) → P(k + 1) is true for all positive integers k. We can reach every rung on the ladder.

Page 9: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Examples:-

Page 10: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Q#1Show that if n is a positive integer, then1 + 2+· · ·+n = n(n + 1)/2

We prove this formula by mathematical induction

Basic step:-

Let p(n) : 1 + 2+· · ·+n = n(n + 1)/2

L.H.S for n=1 R.H.S p(1)=n(n+1)/2

p(1)=1 =1(1+1)/2

=2/2

=1

L.H.S=R.H.S (case 1 is satisfied) it is true.

Inductive step:-

Now assume that p(k) it is true for n=k (where k is +ive integer)

p(k) : 1 + 2+· · ·+k = k(k + 1)/2 eq # 1

(case 2 is satisfied)

Page 11: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Now we have to show that, under the assumption the result is true for p(k+1) for n=k+1.

1 + 2+· · ·+k + (k + 1) = (k + 1)[(k + 1) + 1]/2

= (k + 1)(k + 2)/2 eq # 2

When we add (k + 1) to both sides of the equation in P(k), we obtain

1 + 2+· · ·+k + (k + 1)= k(k + 1)/2+ (k + 1)

= k(k + 1) + 2(k + 1)/2

= (k + 1)(k + 2)/2

Which is same as eq 2.

This last equation shows that P(k + 1) is true under the assumption that P(k) is true. This completes the inductive step.

Hence ,therefore it is true for all +ive integer n.

Page 12: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Q#2Conjecture a formula for the sum of the first n positive odd integers. Then prove your conjecture using mathematical induction.

The sums of the first n positive odd integers n = 1,3,5,7,9,11.....

And so on.

Positive odd numbers Sum of odd numbers

1 (1)2 =1

3 (2)2 =4

5 (3)2 =9

7 (4)2 =16

9 (5)2 =25

4

169

25

Page 13: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

From these values it is reasonable to conjecture that the sum of the first n positive odd integers is n2 .

1 + 3 + 5+· · ·+(2n − 1) = n2 SOLUTION:

Basic step :-

Let P(n) : 1 + 3 + 5+· · ·+(2n − 1) = n2

L.H.S R.H.S

for n=1 for n=1

P(1)=(2(1)-1) p(1)=(1)2

=(2-1) =1

=1

So L.H.S=R.H.S (case 1 is satisfied) it is true.Inductive step:-

Now assume that p(k) it is true for n=k (where k is +ive integer)

p(k) : 1 + 3 + 5+· · ·+(2k − 1) = k2 eq # 1

Page 14: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Now we have to show that, under the assumption the result is true for p(k+1) for n=k+1

1 + 3 + 5+· · ·+(2k-1) + (2(k+1)− 1) = (k+1)2

= (k+1)2 eq # 2

When we add (2k + 1) to both sides of the equation in P(k), we obtain

1 + 3 + 5+· · ·+(2k − 1)+ (2k+1) = k2 + (2k+1)

=k2 + 2k+1

=k2 +k + k+1

= (k+1)(k+1)= (k+1)2

Which is same as eq 2.

Since the result is true for n=K+1, therefore it is true for all +ive integer n.

Page 15: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Note:-• some time we need to show that p(n) is true for n=k ,

n=k+1….. Where k is an integer other than 1.• We can use mathematical induction to accomplish

this as long as we change the basis step. • This proves that the formula is valid for all non

negative integers. So that we need to prove that p(n) is true for n=0, 1 , 2 , 3 , ………..

Page 16: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Q#3 1 + 2 + 22 +· · ·+ 2n = 2n+1 − 1for all nonnegative integers n.

We prove this formula by mathematical induction

Basic step:-

Let p(n) : 1 + 2 + 22 +· · ·+ 2n = 2n+1 − 1

L.H.S for n=0 R.H.S p(0)= 2n+1 − 1

p(0)=20 = 20+1 − 1

=1 = 2 − 1

=1

L.H.S=R.H.S (case 1 is satisfied) it is true.

Inductive step:-

Now assume that p(k) it is true for n=k (where k is +ive integer)

p(k) : 1 + 2 + 22 +· · ·+ 2k = 2k+1 − 1 eq # 1(case 2 is satisfied)

Page 17: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Now we have to show that, under the assumption the result is true for p(k+1) for n=k+1.

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

= 2(k+2) − 1 eq # 2

When we add 2k+1 to both sides of the equation in P(k), we obtain

1 + 2 + 22 +· · ·+ 2k + 2k+1 = 2k+1 − 1 + 2k+1

=2. 2k+1 − 1

= 2(k+2) − 1

Which is same as eq 2.

Since the result is true for n=K+1, therefore it is true for all non negative integer n.

Page 18: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Summation Formula by Mathematical Induction

Page 19: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Q#1 Show that if n is a positive integer, then

We prove this formula by mathematical induction

Basic step:-

Let p(n) :

L.H.S for n=1 R.H.S p(1)=n(n+1)/2

=1(1+1)/2

=2/2

=1

L.H.S=R.H.S (case 1 is satisfied) it is true.

Inductive step:-

Now assume that p(k) it is true for n=k (where k is +ive integer)

p(k) : eq # 1

(case 2 is satisfied)

Page 20: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Now we have to show that, under the assumption the result is true for p(k+1) for n=k+1.

= (k + 1)[(k + 1) + 1]/2

= (k + 1)(k + 2)/2 eq # 2

When we add (k + 1) to both sides of the equation in P(k), we obtain

=k(k + 1)/2+ (k + 1)

= k(k + 1) + 2(k + 1)/2

= (k + 1)(k + 2)/2

Which is same as eq 2.

This last equation shows that P(k + 1) is true under the assumption that P(k) is true. This completes the inductive step.

Since the result is true for n=K+1, therefore it is true for all +ive integer n.

Page 21: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

PROVING INEQUALITIES

Page 22: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Q#1 Use mathematical induction to prove the inequalityn < 2n

for all positive integers n.

Solution:-

Basic step:-

Let p(n) : n < 2n

for n=1

1< 21

1<2 (case 1 is satisfied) it is true

Inductive step:-

Now we assume that it is true for n=k (k is integer +ive)

k< 2k (case 2 is satisfied) it is true

Now we have to show that, under the assumption the result is true for p(k+1) for n=k+1.

(k+1) < 2k+1 eq # 2

Page 23: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

When we add 1 to both sides of the equation in P(k), we obtain

k < 2k, and then note that 1 ≤ 2k.

k+1< 2k + 1

k+1< 2k + 2k

k+1< 2.2k

k+1< 2k+1

Which is same as eq 2.

This shows that P(k + 1) is true, namely, that k+1< 2k+1 based on the assumption that P(k) is true. The induction step is complete.

Hence the result is true for n=K+1, therefore it is true for all +ive integer n.

Page 24: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Q#1 Use mathematical induction to prove that 2n < n !

For n≥ 4. (i.e. n=4,5,6………)

Solution:-

Basic step:-

Let p(n) : 2n < n !

for n=4

24 < 4!

16<4.3.2.1

16 < 24 (case 1 is satisfied) it is true

Inductive step:-

Now we assume that it is true for n=k (k is integer +ive)

2k < k! (case 2 is satisfied) it is true eq # 1

Page 25: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Now we have to show that, under the assumption the result is true for p(k+1) for n=k+1.

2k+1 < (k+1)! eq # 2

From eq # 1

2k < k!

2.2k / 2< k! (multiply or divide by 2 on L.H.S)

2k+1 / 2 < k! (multiply (k+1) on both side)

(k+1).2k+1 /2< (k+1).k! (neglected k+1/2 from L.H.S)

2k+1 < (k+1)!

Which is same as eq 2.

This shows that P(k + 1) is true, namely, that 2k+1 < (k+1)!

based on the assumption that P(k) is true. The induction step is complete.

Hence it is true for every integer n≥ 4.

Page 26: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Strong Induction

Page 27: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Strong Induction:

To prove that P(n) is true for all positive integers n, where P(n) is a propositional function, complete two steps:

BASIS STEP: We verify that the proposition P(1) is true.

INDUCTIVE STEP: We show that the conditional statement [P(1) ∧ P(2) · · · ∧ ∧ P(k)] → P(k + 1) is true for all positive integers k.

Page 28: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Recursion

Page 29: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Definition 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. We can use recursion to define sequences, functions,

and sets. the sequence of powers of 2 is given by an = 2n

for n = 0, 1, 2, . . . . The sequence of powers of 2 can also be defined by giving the first term of the sequence, namely, a0 =

1, and a rule for finding a term of the sequence from the previous one, namely:

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

Page 30: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

.For instance, the picture is produced recursively. First, an original picture is given. Then a process of successively superimposing centered smaller pictures on top of the previous pictures is carried out.

Page 31: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Recursively Defined FunctionsWe use two steps to define a function with the set of nonnegative integers as its domain:

BASIS STEP:

Specify the value of the function at zero.

RECURSIVE STEP:

Give a rule for finding its value at an integer from its values at smaller integers.

Such a definition is called a recursive or inductive definition.

Page 32: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

EXAMPLES

Page 33: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Q # 1

Suppose that f is defined recursively by

f (0) = 3,

f (n + 1) = 2f (n) + 3.

Find f (1), f (2), f (3), and f (4).

Solution:

From the recursive definition it follows that

f (n + 1) = 2f (n) + 3

with 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.

Page 34: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Q # 2

find the f(1), f(2),f(3) and f(4) if f(n) is defined recursively by

f(0)=1 for n=0,1,2,3,4…………

f(n+1)=3f(n)

Solution:from recursively definition.

f(n+1)=3f(n)

with f(0)=1

n=0 : f(1)=3f(0)=3(1)=3

n=1 : f(2)=3f(1)=3(3)=9

n=2 : f(3)=3f(2)=3(9)=27

n=3 : f(4)=3f(3)=3(27)=81

Page 35: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Q # 3Give an inductive (recursive) definition of the factorial function F(n) = n!.

solution:

initial value :

F(0) = 1

recursive form :

F(n+1) = (n+1)!

= n! (n+1)

= F(n) (n+1)

which is deserved rule

Page 36: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Q # 4

Give a recursive definition of:

Solution:

The first part of the recursive definition is a

k = a0 +

a1 +

a2 +………

an

(1) For initial value : (n=0)

(2) For finding a rule : (k=n+1)

=a0 +

a1 +

a2 +………

an + a

n+1

={a0 +

a1 +

a2 +………

an } + a

n+1

= + an+1 which is deserved rule

Page 37: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.

Q # 5

Give the recursive definition of the sequence {an}.

n= 1,2,3,4,5,6…….. a

n =6n

Solution: a

n =6n

(i) For initial value : n=1

a1 =6(1)

a1 =6

(ii) For finding value:

an+1 =6(n+1) an+1 =6n+6 for a

n =6n

an+1 = a

n + 6 n>=1

Page 38: Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.