0% found this document useful (0 votes)
314 views12 pages

Unit 4 - Induction and Recursion - Complete

The document discusses induction and recursion. It defines proof by mathematical induction and strong/complete induction. Mathematical induction proceeds in two steps: the basis step shows a statement is true for the first value, and the inductive step shows if the statement is true for a value k, then it is true for k+1. Strong induction additionally assumes the statement is true for all values up to k in the inductive step. The document provides examples proofs using induction to show formulas for sums and Fibonacci numbers are true for all values. It also introduces the well-ordering property which states any non-empty set of non-negative integers has a least element.

Uploaded by

suman panta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
314 views12 pages

Unit 4 - Induction and Recursion - Complete

The document discusses induction and recursion. It defines proof by mathematical induction and strong/complete induction. Mathematical induction proceeds in two steps: the basis step shows a statement is true for the first value, and the inductive step shows if the statement is true for a value k, then it is true for k+1. Strong induction additionally assumes the statement is true for all values up to k in the inductive step. The document provides examples proofs using induction to show formulas for sums and Fibonacci numbers are true for all values. It also introduces the well-ordering property which states any non-empty set of non-negative integers has a least element.

Uploaded by

suman panta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

UNIT 4.

INDUCTION AND RECURSION 69

Unit 4

Induction and Recursion

4.1 Induction

4.1.1 Proof by mathematical induction


Suppose we have to show that P (n) is true for all integers n greater that equal to n0 i.e., we
have to show that ∀nP (n) is true where the universe of discourse of n is the set of all integers
greater than or equal to n0 . We can use the technique of mathematical induction for proving
such assertions.
The proof by mathematical induction proceeds in two steps:

Basis step: Show that P (n0 ) is true.


Inductive step: Show that P (k) → P (k + 1) is true for any integer k ≥ n0 .

The truth of basis and inductive steps implies the truthness of P (n0 ), P (n0 + 1), P (n0 + 2), · · ·
as follows. The truthness of P (n0 ) is shown in the basis step. The truthness of inductive
step for k = n0 implies that P (n0 ) → P (n0 + 1) is also true and hence by modus ponens,
P (n0 + 1) must be true. Again taking k = n0 + 1 in the inductive step we get the truthness
of P (n0 + 1) → P (n0 + 2) and together with the truthness of P (n0 + 1) we conclude that
P (n0 + 2) is also true. Continuing in this fashion, we can show that P (k) is true for all k ≥ n0 .
Example:

n(n + 1)
1. Show that 1 + 2 + · · · + n = for all n ≥ 1.
2
Proof: We have to prove that
n(n + 1)
1 + 2 + ··· + n =
2
for all n ≥ 1.
Basis step: We have to show that the equality is true for n = 1. When n = 1, we have
LHS = 1

P RAJWAL K ANSAKAR - for CSIT @Prime


UNIT 4. INDUCTION AND RECURSION 70

and
1(1 + 1)
RHS = =1
2
so that LHS = RHS. Hence the equality is true for n = 1.
Inductive step: Suppose that the equality is true when n = k i.e.,

k(k + 1)
1 + 2 + ··· + k = .
2
We now need to prove that the equality is true when n = k + 1 i.e.,

(k + 1)[(k + 1) + 1]
1 + 2 + · · · + k + (k + 1) = .
2
Now,
k(k + 1) k(k + 1) + 2(k + 1)
LHS = 1 + 2 + · · · + k + (k + 1) = + (k + 1) =
2 2
(k + 1)(k + 2) (k + 1)[(k + 1) + 1]
= = = RHS.
2 2
Therefore inductive step is true as well.
n(n + 1)
Hence 1 + 2 + · · · + n = for all n ≥ 1.
2
2. Prove that n3 − n is divisible by 3 for all n ≥ 1.
Proof: We need to prove that n3 − n is divisible by 3 for all n ≥ 1 i.e., n3 − n = 3m for
some integer m.
Basis Step: We show that n3 − n = 3m for some integer m when n = 1. Now when
n = 1, we have
n3 − n = 13 − 1 = 1 − 1 = 0 = 3 × 0.
Hence n3 − n = 3m when n = 1.
Inductive Step: Suppose that n3 − n = 3m for some integer m when n = k i.e., k 3 − k =
3m. We now need to prove that n3 − n is again a multiple of 3 when n = k + 1 i.e.,
(k + 1)3 − (k + 1) is a multiple of 3. Now

(k + 1)3 − (k + 1) = k 3 + 3k 2 + 3k + 1 − k − 1 = k 3 − k + 3(k 2 + k)

= 3m + 3(k 2 + k) = 3(m + k 2 + k).


So (k + 1)3 − (k + 1) is a multiple of 3. Therefore inductive step is true as well.
Hence n3 − n is divisible by 3 for all n ≥ 1.

4.1.2 Proof by strong/complete induction


To prove that P (n) is true for all integers n ≥ n0 , we can use the technique of proof by strong
induction or complete induction that proceeds in two steps as follows:

P RAJWAL K ANSAKAR - for CSIT @Prime


UNIT 4. INDUCTION AND RECURSION 71

Basis step: Show that P (n0 ) is true.


Inductive step: Show that [P (n0 ) ∧ P (n0 + 1) ∧ · · · ∧ P (k)] → P (k + 1) is true
for any integer k ≥ n0 .

Comparing this with the proof by (normal) induction, we can see that the only difference is in
the inductive step: unlike normal induction, in strong induction one assumes the truthness of not
only P (n0 ) but also of P (n0 + 1), · · · , P (k) and uses these to prove the truthness of P (k + 1).
However, it can be proved that both the proof techniques are equivalent i.e., anything that can
be proved using strong induction can also be proved using normal induction and vice-versa.
Example:

1. A Fibonacci sequence {Fn }∞


n=0 is a sequence defined recursively as follows:

F0 = 0, F1 = 1 and Fn+1 = Fn + Fn−1 for n ≥ 2.

So the Fibonacci sequence is 0, 1, 1, 2, 3, 5, 8, 13, · · · .


Show that for each integer n ≥ 0,
 n
7
Fn < .
4

Proof: We need to show that  n


7
Fn <
4
for all n ≥ 0.
Basis step: We need to show that the above inequality is true when n = 0 and n = 1 i.e.,
 0  1
7 7
F0 < and F1 < .
4 4
0 7 1
Since F0 = 0 and 74 = 1, so it is true when n = 0. Since F1 = 1 and 1 <

4
, so it is
true when n = 1 as well.
Inductive step: We now show that if the inequality is true when n = 0, 1, · · · , k, then
0 1 k
it is true for n = k + 1 as well i.e., if F0 < 74 , F1 < 74 , · · · , Fk < 74 , then
k+1
Fk+1 < 47 . Now,
 k  k−1  k−1  
7 7 7 7
Fk+1 = Fk + Fk−1 < + = +1
4 4 4 4
 k−1    k−1  2  k+1
7 11 7 7 7
= < = ,
4 4 4 4 4
k+1
i.e., Fk+1 < 47 .
7 n

Therefore inductive step is true as well. Hence Fn < 4
for any integer n ≥ 0.

P RAJWAL K ANSAKAR - for CSIT @Prime


UNIT 4. INDUCTION AND RECURSION 72

2. Show that if n ≥ 2 is an integer, then n can be written as the product of primes.


Proof: We need to prove that any integer n ≥ 2 can be written as a product of prime
numbers.
Basis step: We shall show that n = 2 can be written as a product of prime numbers. But
this is obviously true because 2 is itself a prime number.
Inductive step: Suppose that all the integers 2, 3, . . . , k where k ≥ 2, can be written as
a product of prime numbers. Then we need to show that k + 1 can also be written as a
product of prime numbers.
Consider the case when k + 1 is itself a prime number. Then our assertion is obviously
true. However if k + 1 is a composite number then k + 1 can be written as a product of
two integers a and b such that 2 ≤ a ≤ b ≤ k + 1. By inductive hypothesis, both a and b
can be written as a product of primes. Therefore k + 1 itself can be written as a product
of primes, namely those primes in the factorization of a and those in the factorization of
b.

4.1.3 Well-Ordering Property


Well-ordering property is one of the fundamental axioms of the set of integers. It states that

“Every nonempty set of nonnegative integers has a least element.”

i.e., if A ⊆ {0, 1, 2, 3, · · · } and A 6= ∅, then A must have a least element. This property can
be used to prove the validity of the principle of mathematical induction as well as the principle
of strong induction. In fact, one can show that the well-ordering property is equivalent to both
these principles of induction.
Example: Use the well-ordering property to prove the division algorithm: “If a is an integer
and d is a positive integer, then there are unique integers q and r with 0 ≤ r < d and a = dq+r.”
Proof: Let
S = {a − dm : a − dm ≥ 0 and m is an integer}.
Then S is a set of nonnegative integers. Also, S is nonempty because by taking m a negative
integer with large absolute value, we can make −dm as large as we like thus making a−dm ≥ 0.
Therefore by the well-ordering property, S has a least element, say r = a − dq. Since r ∈ S,
so r ≥ 0. Also, r < d because if r ≥ d then a − d(q + 1) = a − dq − d = r − d ≥ 0 so
a − d(q + 1) ∈ S. But a − d(q + 1) = r − d < r which contradicts that r is the least element
in S. So 0 ≤ r < d.
To prove the uniqueness of q and r, suppose that there is another pair q1 and r1 with 0 ≤ r1 < d
and a = dq1 + r1 . First we prove that r1 = r. For if not, let r < r1 so that 0 < r − r1 < d
because 0 ≤ r < d and 0 ≤ r1 < d. But

r1 − r = a − dq1 − (a − dq) = d(q − q1 )

i.e., d | (r1 − r) which is impossible because 0 < r − r1 < d. So r ≥ r1 . Similarly, we can


show that r1 ≥ r and therefore r = r1 . Then q = q1 as well.

P RAJWAL K ANSAKAR - for CSIT @Prime


UNIT 4. INDUCTION AND RECURSION 73

4.2 Recursion
The process of defining objects such as functions, sets or sequences in terms of itself is called
recursion. When such objects are defined using recursion, we say that they are recursively
defined.

4.2.1 Recursively-Defined Functions


If a function f is defined for all integers n ≥ n0 in terms of itself, then it is called a recursively-
defined function and such definition of f is called a recursive definition or inductive definition.
We use the following two steps to give a recursive definition of function f :

Basis Step: Specify the value of f at n0 .


Recursive Step: Give a rule for finding its value at an integer n + 1 from its values
at smaller integer.

Examples:

1. Let f be a function defined for all integers n ≥ 0 as follows:

Basis step: f (0) = 3


Recursive step: f (n + 1) = 2f (n) + 3.

Then f is a recursively defined function. Its functional values for integers can be calcu-
lated as follows:

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

and so on.

2. Let f be defined for all integers n ≥ 0 as follows:

Basis step: f (0) = 1


Recursive step: f (n + 1) = (n + 1)f (n).

Then f is a recursive definition of the factorial function f (n) = n!:

f (1) = 1 × f (0) = 1 × 1 = 1 = 1!
f (2) = 2 × f (1) = 2 × 1 = 2!
f (3) = 3 × f (2) = 3 × 2 × 1 = 3!
f (4) = 4 × f (3) = 4 × 3 × 2 × 1 = 4!

and so on.

P RAJWAL K ANSAKAR - for CSIT @Prime


UNIT 4. INDUCTION AND RECURSION 74

3. While defining a recursive function, basis step may require declaration of functional val-
ues at more than one initial point as in example below:

Basis step: f (0) = 0, f (1) = 1


Recursive step: f (n + 1) = f (n) + f (n − 1).

Then

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

and so on.

4. Recursive definition of the power function f (n) = an where a 6= 0 and n ≥ 0:

Basis step: f (0) = 1


Recursive step: f (n + 1) = af (n).
m
X
5. Recursive definition of the summation function f (m) = ak :
k=0

Basis step: f (0) = a0


Recursive step: f (n + 1) = f (n) + an+1 .

4.2.2 Recursively Defined Sets


If a set S is defined in terms of itself, then S is called a recursively defined set and such definition
of S is called recursive definition or inductive definition.
We use the following two steps to give a recursive definition of set S:

Basis Step: Specify the elements that initially belongs to the set S.
Recursive Step: Give rules for forming new elements in the set S from those
already known to be in S.

Examples:

1. Let S be the set defined recursively as follows:

Basis Step: 3 ∈ S
Recursive Step: If x, y ∈ S then x + y ∈ S.

Then S is the set of all the positive multiples of 3.

2. Let S be the set defined recursively as

P RAJWAL K ANSAKAR - for CSIT @Prime


UNIT 4. INDUCTION AND RECURSION 75

Basis Step: 5 ∈ S
Recursive Step: If x, y ∈ S, then x + y ∈ S and x − y ∈ S.

Then S is the set of all the possible integer multiples of 5.

3. Let S be the set of all well-formed formulae for compound propositions formed from T ,
F , propositional variables p, q, r, s etc and logical operators ¬, ∧, ∨, →, ↔. Then S can
be defined recursively as follows:

Basis Step: T , F and propositional variables such as p, q, r, s etc are well-


defined formulae.
Recursive Step: If U and V are well-formed formulae then (¬U ), (U ∧V ), (U ∨
V ), (U → V ) and (U ↔ V ) are also well-formed formulae.

4.2.3 Structural Induction


To prove results about recursively defined sets, we use a form of mathematical induction which
is called structural induction. A proof by structural induction consists of two steps:

Basis Step: Show that the result holds for all elements specified in the basis step of
the recursive definition of the set.
Recursive Step: Show that if the statement is true for each of the elements used to
construct new elements in the recursive step of the definition, the result holds for
these new elements.

Example:

1. Show that the set S defined recursively in previous example 1. is the set of all the positive
integers that are multiples of 3.
Proof: We have to prove that if x is any element of the set S, then x = 3m for some
positive integer m. We proceed by structural induction.
Basis step: Since 3 = 3 × 1 is a positive integer multiple of 3, so the result holds for the
element 3 specified in the basis step of recursive definition.
Recursive step: Now suppose x, y are some positive integer multiples of 3 i.e., x = 3m
and y = 3n for some positive integers m and n. Then

x + y = 3m + 3n = 3(m + n)

is also a positive integer multiple of 3 and so the result holds.

2. Show that every well-formed formulae for compound propositions contains an equal num-
ber of left and right parentheses.
Proof:
Basis step: Since the formulae T , F , p, q, r, s etc do not have any parentheses, so they
have an equal number (i.e. zero number) of left and right parentheses.

P RAJWAL K ANSAKAR - for CSIT @Prime


UNIT 4. INDUCTION AND RECURSION 76

Recursive step: Now suppose U and V are well-formed formulae each containing an
equal number of left and right parentheses. That is, if LU , RU , LV , RV are the number
of left and right parentheses in U and V respectively then LU = RU and LV = RV . To
complete the induction step, we need to show that (¬U ), (U ∧ V ), (U ∨ V ), (U → V ),
(U ↔ V ) also contain an equal number of left and right parentheses. The number of left
parentheses in (¬U ) is LU + 1 and in others there are LU + LV + 1. The number of right
parentheses in (¬U ) is RU + 1 and in others there are RU + RV + 1. Since LU = RU and
LV = RV , so LU + 1 = RU + 1 and LU + LV + 1 = RU + RV + 1. Therefore each of
these compound propositions also contain the same number of left and right parentheses.

4.2.4 Recursive Algorithms


An algorithm that solves a problem by reducing it to an instance of the same problem but with
smaller input is called a recursive algorithm.

1. Recursive algorithm for computing n!, n ≥ 0:


The factorial of an integer n, denoted by n!, is defined as n! = 1 if n = 0 and n! =
1 × 2 × 3 × · · · × (n − 1) × n if n ≥ 1. The following is a recursive algorithm to compute
n!.

Procedure factorial(n : nonnegative integer)


IF n = 0 THEN factorial(n) = 1
ELSE factorial(n) = n· factorial(n − 1)

2. Recursive algorithm for computing an , a 6= 0, n ≥ 0:


For a number a 6= 0 and an integer n ≥ 0, we define an as an = 0 if n = 0 and
an+1 = a · an if n ≥ 1. So the following gives the recursive algorithm to compute an .

Procedure power(a: nonzero real number; n : nonnegative integer)


IF n = 0 THEN power(a, n) = 1
ELSE power(a, n) = a· power(a, n − 1)

3. Recursive algorithm for computing gcd(a, b):


While computing gcd(a, b) where a < b are nonnegative integers, if the integer a is zero,
then gcd(0, b) = b. Otherwise if a 6= 0, then gcd(a, b) is equal to the gcd of a and the
remainder obtained when b is divided by a i.e. gcd(a, b) = gcd(b mod a, a). So we can
form a recursive algorithm for computing gcd(a, b) as follows:

Procedure gcd(a, b : nonnegative integers with a < b)


IF a = 0 THEN gcd(a, b) = b
ELSE gcd(a, b) = gcd(b mod a, a)

4. Recursive algorithm for linear search:


This algorithm searches for x in the sequence ai , ai+1 , . . . , aj .

P RAJWAL K ANSAKAR - for CSIT @Prime


UNIT 4. INDUCTION AND RECURSION 77

Procedure search(i, j, x : i, j are integers with 1 ≤ i, j ≤ n and x a number)


IF ai = x THEN location = i
ELSE IF i = j THEN location = 0
ELSE search(i + 1, j, x)

5. Recursive algorithm for modular exponentiation:


Given integers b, n and m where n ≥ 0 and m ≥ 2, this algorithm computes bn mod m
i.e. the remainder when bn is divided by m.

Procedure mpower(b, n, m : integers with m ≥ 2, n ≥ 0)


IF n = 0 THEN mpower(b, n, m) = 1
ELSE IF n is even THEN mpower(b, n, m) = mpower(b, n/2, m)2
mod m
ELSE mpower(b, n, m) = (mpower(b, bn/2c, m)2 mod m · b mod m)
mod m

Proving correctness of recursive algorithm

1. Prove that the algorithm to compute an for a 6= 0 and n ≥ 0 an integer, is correct.


Solution: We have to prove that power(a, n)= an for all n ≥ 0. For this, we use the
process of mathematical induction on the exponent n.
Basis Step: We prove that power(a, n)= an when n = 0. Now when n = 0, we have
power(a, 0)= 1 from the algorithm and also a0 = 1 for nonzero a. Therefore

LHS = RHS

when n = 0.
Inductive Step: Suppose that the equality is true when n = k i.e.,

power(a, k) = ak .

We have to prove that the equality is true when n = k + 1 i.e.,

power(a, k + 1) = ak+1 .

Now since n = k + 1 is greater than 0, so by the algorithm, we have

power(a, k + 1) = a · power(a, k).

But by the inductive hypothesis, we have power(a, k) = ak and so

power(a, k + 1) = a · power(a, k) = a · ak = ak+1 .

Hence the inductive step is also true and therefore, power(a, n) = an for all n ≥ 0.

P RAJWAL K ANSAKAR - for CSIT @Prime


UNIT 4. INDUCTION AND RECURSION 78

2. Prove that the algorithm to compute n! for n ≥ 0 is correct.


Solution: We have to prove that factorial(n) = n! for all n ≥ 0. For this, we use the
process of mathematical induction on the integer n.
Basis Step: We prove that factorial(n) = n! when n = 0. Now when n = 0, we have
factorial(0) = 1 from the algorithm and also 0! = 1 by the definition of the factorial of
an integer. Therefore
LHS = RHS
when n = 0.
Inductive Step: Suppose that the equality is true when n = k i.e.,

f actorial(k) = k!.

We have to prove that the equality is true when n = k + 1 i.e.,

f actorial(k + 1) = (k + 1)!.

Now since n = k + 1 is greater than 0, so by the algorithm, we have

f actorial(k + 1) = (k + 1) · f actorial(k).

But by the inductive hypothesis, we have factorial(k) = k! and so

f actorial(k + 1) = (k + 1) · f actorial(k) = (k + 1) · k! = (k + 1)!.

Hence the inductive step is also true and therefore, factorial(n) = n! for all n ≥ 0.

P RAJWAL K ANSAKAR - for CSIT @Prime


UNIT 4. INDUCTION AND RECURSION 79

4.3 Exercise

4.3.1 Induction
1. Use mathematical induction to prove the following:
n(n + 1)(2n + 1)
(a) 12 + 22 + · · · n2 = for n ≥ 1.
6
n(n + 1)(n + 2)
(b) 1.2 + 2.3 + .... + n(n + 1) = for n ≥ 1.
3
 2
3 3 3 n(n + 1)
(c) 1 + 2 + .... + n = for n ≥ 1.
2
n(2n − 1)(2n + 1)
(d) 12 + 32 + · · · + (2n − 1)2 = for n ≥ 1.
3
1 1 1 n
(e) + + ··· + = for n ≥ 1.
1·2 2·3 n(n + 1) n+1
(f) 1 + 2 + 22 + · · · + 2n = 2n+1 − 1 for all n ≥ 0.
(g) 1.1! + 2.2! + · · · + n.n! = (n + 1)! − 1 for all n ≥ 1.
(h) The sum of the first n odd positive integers is n2 i.e. 1 + 3 + 5 + · · · + (2n − 1) = n2
for all n ≥ 1.
(i) If 0 ≤ a < 1 then show that (1 − a)n ≥ 1 − na for all n ≥ 1.
(j) f02 + f12 + · · · + fn2 = fn fn+1 for all n ≥ 0 where fi ’s are the ith Fibonacci numbers.
(k) Prove that n2 + n is divisible by 2 for all n ≥ 1.
(l) Prove that 3 divides n3 + 2n whenever n is a positive integer.
(m) Prove that 5 divides n5 − n for all n ≥ 0.
(n) Prove that n3 − n is divisible by 6 whenever n ≥ 0.
(o) 2n < n! for all n ≥ 4.
(p) n2 < 2n for all n ≥ 5.

2. Use strong
 induction to prove that the nth Fibonacci number Fn satisfies the inequality
n
13
Fn < for n ≥ 1.
8

4.3.2 Recursion
1. Find a recursive definition of the functions

(a) f (n) = n2 , n ≥ 0
(b) f (n) = 2n + 1, n ≥ 1
1
(c) f (n) = , n ≥ 1
n
P RAJWAL K ANSAKAR - for CSIT @Prime
UNIT 4. INDUCTION AND RECURSION 80

2. Give a recursive definition of the set

(a) of all odd positive integers


(b) of all even integers
(c) of all positive integer powers of 3
(d) of all positive integers not divisible by 5
(e) of all positive integers congruent to 2 modulo 3

3. Trace the recursive factorial algorithm for n = 7.


4. Trace the recursive power algorithm for a = 3 and n = 6.
5. Trace the recursive gcd algorithm for a = 272, b = 1479.

P RAJWAL K ANSAKAR - for CSIT @Prime

You might also like