You are on page 1of 83

4.

1 Mathematical Induction
4.2 Strong Induction and Well-Ordering
4.3 Recursive Definitions and Structural Induction
4.4 Recursive Algorithms
4.5 Program Correctness
4.6 Solutions to Recursive Relations with Constant Coefficients

Chapter 4. Induction and Recursion

Do Ngoc Diep

May 10, 2018

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering
4.3 Recursive Definitions and Structural Induction
4.4 Recursive Algorithms
4.5 Program Correctness
4.6 Solutions to Recursive Relations with Constant Coefficients

Discussion

What are we doing in this chapter?


I 4.1 Mathematical Induction

I 4.2 Strong Induction and Well-Ordering

I 4.3 Recursive Definitions and Structural Induction

I 4.4 Recursive Algorithms

I 4.5 Program Correctness

I 4.6 Solution of Recursive Relations

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Mathematical Induction
4.3 Recursive Definitions and Structural Induction Examples of Proofs by Mathematical Induction
4.4 Recursive Algorithms Why Mathematical Induction is Valid
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Principle of Induction

In general, mathematical induction can be used to prove


statements that assert that P(n) is true for all positive
integers n, where P(n) is a propositional function. A proof by
mathematical induction has two parts, a
basis step, where we show that P(1) is true, and an
inductive step, where we show that for all positive integers k,
if P(k) is true, then P(k + 1) is true.

[P(1) ∧ ∀k(P(k) → P(k + 1))] → ∀nP(n),

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Mathematical Induction
4.3 Recursive Definitions and Structural Induction Examples of Proofs by Mathematical Induction
4.4 Recursive Algorithms Why Mathematical Induction is Valid
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Mathematical Induction
4.3 Recursive Definitions and Structural Induction Examples of Proofs by Mathematical Induction
4.4 Recursive Algorithms Why Mathematical Induction is Valid
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Mathematical Induction
4.3 Recursive Definitions and Structural Induction Examples of Proofs by Mathematical Induction
4.4 Recursive Algorithms Why Mathematical Induction is Valid
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Examples
Example
Show that if n is a positive integer, then
n(n+I )
I 1 + 2 + ··· + n = .
2
I 1 + 3 + 5 + · · · + (2n − 1) = n 2 .

I 1 + 2 + 22 + · · · + 2n = 2n+1 − 1

I Geometric Progression Sum


( n+1
ar −a
Pn j r −1
, when r 6= 1
j=0 ar =
(n + 1)a when r = 1
I n < 2 n

I 2n < n!

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Mathematical Induction
4.3 Recursive Definitions and Structural Induction Examples of Proofs by Mathematical Induction
4.4 Recursive Algorithms Why Mathematical Induction is Valid
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Example
I An Inequality for Harmonic Numbers
Hj = 1 + 21 + 13 · · · + 1j , then H2n > 1 + n2 .
I Use mathematical induction to prove that n3 − n is
divisible by 3 whenever n is a positive integer.
I Use mathematical induction to show that if S is a finite
set with n elements where n is a nonnegative integer,
then S has 2n subsets.
I Generalized de Morgan laws: ∩nj=1 Aj = ∪nj=1 Aj

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Mathematical Induction
4.3 Recursive Definitions and Structural Induction Examples of Proofs by Mathematical Induction
4.4 Recursive Algorithms Why Mathematical Induction is Valid
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Validity of Math. Induction


Why is mathematical induction a valid proof technique? The
reason comes from the well-ordering property listed in
Appendix 1 as an axiom for the set of positive integers.
Suppose we know that P(1) is true and that the proposition
P(k) → P(k + 1) is true for all positive integers k. To show
that P(n) must be true for all positive integers n, assume that
there is at least one positive integer for which P(n) is false.
Then the set S of positive integers for which P(n) is false is
nonempty. Thus, by the well-ordering property,
Axiom 4 The Well-Ordering Property Every
nonempty subset of the set of positive integers has a
least element.
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Mathematical Induction
4.3 Recursive Definitions and Structural Induction Examples of Proofs by Mathematical Induction
4.4 Recursive Algorithms Why Mathematical Induction is Valid
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Validity of Math. Induction

S has a least element, which will be denoted by m. We know


that m cannot be 1, because P(1) is true. Because m is
positive and greater than 1, m − 1 is a positive integer.
Furthermore, because m − 1 is less than m, it is not in S, so
P(m − 1) must be true. Because the conditional statement
P(m − 1) → P(m) is also true, it must be the case that P(m)
is true. This contradicts the choice of m.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Mathematical Induction
4.3 Recursive Definitions and Structural Induction Examples of Proofs by Mathematical Induction
4.4 Recursive Algorithms Why Mathematical Induction is Valid
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Exercises

No 8(mod 10): 8, 18, 28, 38, 48 .

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Mathematical Induction
4.3 Recursive Definitions and Structural Induction Examples of Proofs by Mathematical Induction
4.4 Recursive Algorithms Why Mathematical Induction is Valid
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Write your answers on a paperwork


Exercises
8 Prove that
2 − 2.7 + 2.72 + · · · + 2(−7)n = (1 − (−7)n+1 )/4
whenever n is a nonnegative integer.
18 Let P(n) be the statement that n! < nn , where n is an
integer greater than 1. a) What is the statement P(2)?
b) Show that P(2) is true, completing the basis step of
the proof.
28 Prove that n2 − 7n + 12 is nonnegative whenever n is an
interger with n ≥ 3.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Mathematical Induction
4.3 Recursive Definitions and Structural Induction Examples of Proofs by Mathematical Induction
4.4 Recursive Algorithms Why Mathematical Induction is Valid
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Exercises
38 Prove that if A1 , A2 , ..., An and B1 , B2 , ..., Bn are sets such
that Aj ⊆ Bj for j = 1, 2, ..., n, then
n
[ n
[
Aj ⊆ Bj .
j=1 j=1

48 What is wrong with this ”proof”?


”Theorem”
Pn For every positive integer n,
1 2
i=1 i = (n + 2 ) /2.
Basis Step: The formula is true Pfor n = 1.
n
Inductive Step: Suppose that i=1 i = (n + 21 )2 /2. Then
Pn+1 1 2 2 1
i=1 i = (n + 2 ) /2 + n + 1 = (n + n + 4 )/2 + n + 1
= (n2 + 3n + 4 = (n + 2 )2 /2 = [(n + 1) + 12 ]2 /2,
9 3

completing the inductive step.


Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
Strong Induction
4.2 Strong Induction and Well-Ordering
Examples of Proofs Using Strong Induction
4.3 Recursive Definitions and Structural Induction
Using Strong Induction in Computational Geometry
4.4 Recursive Algorithms
Proofs Using the Well-Ordering Property
4.5 Program Correctness
Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

STRONG 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: 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 + I ) is true for all positive
integers k.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
Strong Induction
4.2 Strong Induction and Well-Ordering
Examples of Proofs Using Strong Induction
4.3 Recursive Definitions and Structural Induction
Using Strong Induction in Computational Geometry
4.4 Recursive Algorithms
Proofs Using the Well-Ordering Property
4.5 Program Correctness
Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Examples
2 Fundamental Theorem of Arithmetic that tells us that
every positive integer can be written as the product of
primes.
3 Show that if n is an integer greater than I, then n can be
written as the product of primes.
4 Prove that every amount of postage of 12 cents or more
can be formed using just 4-cent and 5-cent stamps.
Solution. Basic step. Postage of 12 cents can be formed
using three 4-cent stamps. Inductive step: The
hypothesis P(k) is true: postage of k cents can be formed
using 4-cent and 5-cent stamps.
We assume P(k) is true, then P(k + I) is also true where
k ≥ 12.
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
Strong Induction
4.2 Strong Induction and Well-Ordering
Examples of Proofs Using Strong Induction
4.3 Recursive Definitions and Structural Induction
Using Strong Induction in Computational Geometry
4.4 Recursive Algorithms
Proofs Using the Well-Ordering Property
4.5 Program Correctness
Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Example
...4 That is, we need to show that if we can form postage of k
cents, then we can form postage of k + 1 cents:
If at least one 4-cent stamp was used to form postage of
k cents. Then we can replace this stamp with a 5-cent
stamp to form postage of k + I cents.
But if no 4-cent stamps were used, we can form postage
of k cents using only 5-cent stamps. Moreover, because
k ≥ 12, we needed at least three 5-cent stamps to form
postage of k cents. So, we can replace three 5-cent
stamps with four 4-cent stamps to form postage of k + 1
cents.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
Strong Induction
4.2 Strong Induction and Well-Ordering
Examples of Proofs Using Strong Induction
4.3 Recursive Definitions and Structural Induction
Using Strong Induction in Computational Geometry
4.4 Recursive Algorithms
Proofs Using the Well-Ordering Property
4.5 Program Correctness
Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Example
...4 Because we have completed the basis step and the
inductive step, we know that P(n) is true for all n ≥ 12.
That is, we can form postage of n cents, where n ≥ 12
using just 4-cent and 5-cent stamps. Next, we will use
strong induction to prove the same result. In this proof,
in the basis step we show that P(12), P(13), P(14), and
P(15) are true, that is, that postage of 12,13, 14, or 15
cents can be formed using just 4-cent and 5-cent stamps.
In the inductive step we show how to get postage of
k + 1 cents for k ≥ 15 from postage of k − 3 cents.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
Strong Induction
4.2 Strong Induction and Well-Ordering
Examples of Proofs Using Strong Induction
4.3 Recursive Definitions and Structural Induction
Using Strong Induction in Computational Geometry
4.4 Recursive Algorithms
Proofs Using the Well-Ordering Property
4.5 Program Correctness
Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Lemma
Every simple polygon has an interior diagonal.
Theorem
A simple polygon with n sides, where n is an integer with
n ≥ 3, can be triangulated into n − 2 triangles.
Proof. using strong induction. Let T (n) be the statement that
every simple polygon with n sides can be triangulated into
n − 2 triangles. BASIS STEP: T (3) is true because a simple
polygon with three sides is a triangle. INDUCTIVE STEP: For
the inductive hypothesis, we assume that T (j) is true for all
integers j with 3 ≤ j ≤ k. To complete the inductive step, we
must show that when we assume the inductive hypothesis,
P(k + 1) is true, that is, that every simple polygon with k + I
sides can be triangulated into (k + I ) − 2 = k − I triangles. 
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
Strong Induction
4.2 Strong Induction and Well-Ordering
Examples of Proofs Using Strong Induction
4.3 Recursive Definitions and Structural Induction
Using Strong Induction in Computational Geometry
4.4 Recursive Algorithms
Proofs Using the Well-Ordering Property
4.5 Program Correctness
Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

We have a simple polygon P with k + 1 sides. By Lemma 1, P


has an interior diagonal ab. Now, ab splits P into two simple
polygons Q, with s sides, and R, with 1 sides. The sides of Q
and R are the sides of P, together with the side ab, which is a
side of both Q and R. Note that 3 ≤ s ≤ k and 3 ≤ t ≤ k
because both Q and R have at least one fewer side than P
does (after all, each of these is formed from P by deleting at
least two sides and replacing these sides by the diagonal ab).
Furthermore, the number of sides of P is two less than the
sum of the numbers of sides of Q and the number of sides of
R, because each side of P is a side of either Q or of R, but
not both, and the diagonal ab is a side of both Q and R, but
not P. That is, k + I = s + 1 − 2.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
Strong Induction
4.2 Strong Induction and Well-Ordering
Examples of Proofs Using Strong Induction
4.3 Recursive Definitions and Structural Induction
Using Strong Induction in Computational Geometry
4.4 Recursive Algorithms
Proofs Using the Well-Ordering Property
4.5 Program Correctness
Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

By the inductive hypothesis, because both 3 ≤ s ≤ k and


3 ≤ t ≤ k, we can triangulate Q and R into s − 2 and t − 2
triangles, respectively. Next, note that these triangulations
together produce a triangulation of P. (Each diagonal added
to triangulate one of these smaller polygons is also a diagonal
of P.) Consequently, we can triangulate P into a total of
(s − 2) + (t − 2) = s + t − 4 = (k + I ) − 2 triangles. This
completes the proof by strong induction.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
Strong Induction
4.2 Strong Induction and Well-Ordering
Examples of Proofs Using Strong Induction
4.3 Recursive Definitions and Structural Induction
Using Strong Induction in Computational Geometry
4.4 Recursive Algorithms
Proofs Using the Well-Ordering Property
4.5 Program Correctness
Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

The validity of both the principle of mathematical induction


and strong induction follows from a fundamental axiom of the
set of integers, the well-ordering property
THE WELL-ORDERING PROPERTY Every nonempty set of
nonnegative integers has a least element.
Example
Use the well-ordering property to prove the division algorithm.
Recall that the division algorithm states that 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 .

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
Strong Induction
4.2 Strong Induction and Well-Ordering
Examples of Proofs Using Strong Induction
4.3 Recursive Definitions and Structural Induction
Using Strong Induction in Computational Geometry
4.4 Recursive Algorithms
Proofs Using the Well-Ordering Property
4.5 Program Correctness
Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Example. In a round-robin tournament every player plays


every other player exactly once and each match has a winner
and a loser. We say that the players P1 , P2 , ..., Pm form a cycle
if P1 beats P2 , P2 beats P3 , ..., Pm−I beats Pm , and Pm beats
P1 . Use the well-ordering principle to show that if there is a
cycle oflength m(m ≥ 3) among the players in a round-robin
tournament, there must be a cycle of three of these players.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
Strong Induction
4.2 Strong Induction and Well-Ordering
Examples of Proofs Using Strong Induction
4.3 Recursive Definitions and Structural Induction
Using Strong Induction in Computational Geometry
4.4 Recursive Algorithms
Proofs Using the Well-Ordering Property
4.5 Program Correctness
Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Solution: We assume that there is no cycle of three players.


Consider the first three elements of this cycle, P1 , P2 , and P3 .
There are two possible outcomes of the match between PI and
P3 . If P3 beats P1 it follows that P1 , P2, P3 is a cycle of
length three, contradicting our assumption that there is no
cycle of three players. Consequently, it must be the case that
PI beats P3 . Remove P2 from any cycle.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
Strong Induction
4.2 Strong Induction and Well-Ordering
Examples of Proofs Using Strong Induction
4.3 Recursive Definitions and Structural Induction
Using Strong Induction in Computational Geometry
4.4 Recursive Algorithms
Proofs Using the Well-Ordering Property
4.5 Program Correctness
Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Exercises

No 3 (mod 10): 3, 23, 33.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
Strong Induction
4.2 Strong Induction and Well-Ordering
Examples of Proofs Using Strong Induction
4.3 Recursive Definitions and Structural Induction
Using Strong Induction in Computational Geometry
4.4 Recursive Algorithms
Proofs Using the Well-Ordering Property
4.5 Program Correctness
Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

3 Let P(n) be the statement that a postage of n cents can


be formed using just 3-cent stamps and 5-cent stamps.
The parts of this exercise outline a strong induction proof
that p(n) is true for n, n ≥ 8.
a) Show that the statements P(8), P(9), and P(10) are
true, completing the basis step of the proof.
b) What is the inductive hypothesis of the proof?
c) What do you need to prove in the inductive step?
d) Complete the inductive step for k ≥ 10.
e) Explain why these steps show that this statement is
true whenever n ≥ 8.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
Strong Induction
4.2 Strong Induction and Well-Ordering
Examples of Proofs Using Strong Induction
4.3 Recursive Definitions and Structural Induction
Using Strong Induction in Computational Geometry
4.4 Recursive Algorithms
Proofs Using the Well-Ordering Property
4.5 Program Correctness
Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

23 Let E (n) be the statement that in a triangulation of a


simple polygon with n sides, at least one of the triangles
in the triangulation has two sides bordering the exterior of
the polygon.
a) Explain where a proof using strong induction that E (n)
is true for all integers n ≥ 4 runs into difficulties.
b) Show that we can prove that E (n) is true for all
integers n ≥ 4 by proving by strong induction the
stronger statement T (n) for all integers n ≥ 4, which
states that in every triangulation of a simple polygon, at
least two of the triangles in the triangulation have two
sides bordering the exterior of the polygon.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
Strong Induction
4.2 Strong Induction and Well-Ordering
Examples of Proofs Using Strong Induction
4.3 Recursive Definitions and Structural Induction
Using Strong Induction in Computational Geometry
4.4 Recursive Algorithms
Proofs Using the Well-Ordering Property
4.5 Program Correctness
Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

33 Show that we can prove that P(n, k) is true for all pairs
of positive integers n and k if we show
a) P(1, 1) is true and
P(n, k) → [P(n + 1, k) ∧ P(n, k + 1)] is true for all
positive integers n and k. b) P(1, k) is true for all
positive integers k, and P(n, k) → P(n + 1, k) is true for
all positive integers n and k. c) P(n, 1) is true for all
positive integers n, and P(n, k) → P(n, k + 1) is true for
all positive integers n and k.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Recursively Defined Functions
4.3 Recursive Definitions and Structural Induction Recursively Defined Sets and Structures
4.4 Recursive Algorithms Structural Induction
4.5 Program Correctness Generalized Induction
4.6 Solutions to Recursive Relations with Constant Coefficients Exercises

Recursive Picture

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Recursively Defined Functions
4.3 Recursive Definitions and Structural Induction Recursively Defined Sets and Structures
4.4 Recursive Algorithms Structural Induction
4.5 Program Correctness Generalized Induction
4.6 Solutions to Recursive Relations with Constant Coefficients Exercises

We 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.
Example
I 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).
I The Fibonacci numbers, f0 , f1 , f2 , ..., are defined by the
equations f0 = 0, f1 = 1, and fn = fn−I + fn−2 for
n = 2, 3, 4, ....

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Recursively Defined Functions
4.3 Recursive Definitions and Structural Induction Recursively Defined Sets and Structures
4.4 Recursive Algorithms Structural Induction
4.5 Program Correctness Generalized Induction
4.6 Solutions to Recursive Relations with Constant Coefficients Exercises

Example √
Show that whenever n ≥ 3, fn > αn−2 , where α = (1 + 5)/2.
Theorem
LAME’S THEOREM Let a and b be positive integers with
a ≥ b. Then the number of divisions used by the Euclidean
algorithm to find gcd(a, b) is less than or equal to five times
the number of decimal digits in b.
Proof.
r0 = r1 q1 + r2 , 0 ≤ r2 < r1 ,
r1 = r2 q2 + r3 , 0 ≤ r3 < r2 , etc...
rn−2 = rn−1 qn−1 + rn , 0 ≤ rn < rn−1 ,

Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Recursively Defined Functions
4.3 Recursive Definitions and Structural Induction Recursively Defined Sets and Structures
4.4 Recursive Algorithms Structural Induction
4.5 Program Correctness Generalized Induction
4.6 Solutions to Recursive Relations with Constant Coefficients Exercises

Proof.

rn−1 = rn qn , rn = gcd(a, b), q1 , q2 , . . . , qn−1 > 1

rn
1 = f2 , ≥

2rn ≥ 2f2 = f3 ,
rn−1

rn−1 + rn ≥ f3 + f2 = f4 , etc....
rn−2

r3 + r4 ≥ fn−1 + fn−2 = fn
r2
r1 ≥ r2 + r3 ≥ fn + fn−1 = fn+1 .
b =

log b > (n−1) log α > (n−1)/5, log α = log(1+ 5)/2 ≈ 0.208 > 1/
Now suppose that b has k decimal digits. Then b < 10k and
log b < k. It follows that n − 1 < 5k, and because k is an
integer, it follows that n ≤ 5k. 
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Recursively Defined Functions
4.3 Recursive Definitions and Structural Induction Recursively Defined Sets and Structures
4.4 Recursive Algorithms Structural Induction
4.5 Program Correctness Generalized Induction
4.6 Solutions to Recursive Relations with Constant Coefficients Exercises

Sets can be defined recursively. Just as in the recursive


definition of functions, recursive definitions of sets have two
parts, a basis step and a recursive step. In the basis step, an
initial collection of elements is specified. In the recursive step,
rules for forming new elements in the set from those already
know to be in the set are provided. Recursive definitions may
also include an exclusion rule, which spedfies that a recursively
defined set contains nothing other than those elements
specified in the basis step or generated by applications of the
recursive step.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Recursively Defined Functions
4.3 Recursive Definitions and Structural Induction Recursively Defined Sets and Structures
4.4 Recursive Algorithms Structural Induction
4.5 Program Correctness Generalized Induction
4.6 Solutions to Recursive Relations with Constant Coefficients Exercises

Structural Induction

Example 13 Show that every well-formed formulae for


compound propositions, as defined in Example 10, contains an
equal number of left and right parentheses.
BASIS STEP: Show that the result is true for T , F , and s
whenever s is a propositional variable.
RECURSIVE STEP: Show that if the result is true for the
compound propositions p and q, it is also true for
(¬p), (p ∨ q), (p ∧ q), (p → q), and (p ↔ q).

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Recursively Defined Functions
4.3 Recursive Definitions and Structural Induction Recursively Defined Sets and Structures
4.4 Recursive Algorithms Structural Induction
4.5 Program Correctness Generalized Induction
4.6 Solutions to Recursive Relations with Constant Coefficients Exercises

Generalized Induction

As an example, note that we can define an ordering on N × N,


the ordered pairs of nonnegative integers, by specifying that
(X1 , Y1 ) is less than or equal to (X2 , Y2 ) if either X1 < X 2, or
X |1 = X2 and Y1 < Y 2; this is called the lexicograpbic
ordering.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Recursively Defined Functions
4.3 Recursive Definitions and Structural Induction Recursively Defined Sets and Structures
4.4 Recursive Algorithms Structural Induction
4.5 Program Correctness Generalized Induction
4.6 Solutions to Recursive Relations with Constant Coefficients Exercises

Exercises

No 5(mod 10): 5, 25, 35, 45, 55, 65.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Recursively Defined Functions
4.3 Recursive Definitions and Structural Induction Recursively Defined Sets and Structures
4.4 Recursive Algorithms Structural Induction
4.5 Program Correctness Generalized Induction
4.6 Solutions to Recursive Relations with Constant Coefficients Exercises

5 Determine whether each of these proposed definitions is a


valid recursive definition of a function f from the set of
nonnegative integers to the set of integers. If f is well
defined, find a formula for f (n) when n is a nonnegative
integer and prove that your formula is valid.
a) f (0) = 0, f (n) = 2f (n − 2) for n ≥ 1
b) f (0) = 1, f (n) = f (n − 1) − 1, for n ≥ 1
c) f (0) = 2, (1) = 3, f (n) = f (n − 1) − I for n ≥ 2
d) f (0) = 1, f (1) = 2, f (n) = 2f (n − 2) for n ≥ 2
e)f (0) = 1, f (n) = 3f (n − 1)if n is odd and n ≥ 1 and
f (n) = 9f (n − 2) if n is even and n ≥ 2

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Recursively Defined Functions
4.3 Recursive Definitions and Structural Induction Recursively Defined Sets and Structures
4.4 Recursive Algorithms Structural Induction
4.5 Program Correctness Generalized Induction
4.6 Solutions to Recursive Relations with Constant Coefficients Exercises

25 Give a recursive definition of a) the set of even integers.


b) the set of positive integers congruent to 2 modulo 3.
c) the set of positive integers not divisible by 5.
35 Give a recursive definition of the reversal of a string.
[Hint: First define the reversal of the empty string. Then
write a string w of length n + 1 as xy , where x is a string
of length n, and express the reversal of w in terms of x R
and y .]
45 Use generalized induction as was done in Example 15 to 0
and show that if am,n is defined recursively by a0,0 = 0
(
am−1,n + 1 if n = 0 and m > 0,
am,n =
am,n−1 + 1 if n > 0.
then am,n = m + n for all (m, n) ∈ N × N.
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Recursively Defined Functions
4.3 Recursive Definitions and Structural Induction Recursively Defined Sets and Structures
4.4 Recursive Algorithms Structural Induction
4.5 Program Correctness Generalized Induction
4.6 Solutions to Recursive Relations with Constant Coefficients Exercises

55 Consider an inductive definition of a version of


Ackermann’s function. This function was named after
Wilhelm Ackermann, a German mathematician who was a
student of the great mathematician David Hilbert.
Ackermann’s function plays an im- portant role in the
theory of recursive functions and in the study of the
complexity of certain algorithms involving set unions.
(There are several different variants of this function. All
are called Ackermann’s function and have similar
properties even though their values do not always agree.)

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Recursively Defined Functions
4.3 Recursive Definitions and Structural Induction Recursively Defined Sets and Structures
4.4 Recursive Algorithms Structural Induction
4.5 Program Correctness Generalized Induction
4.6 Solutions to Recursive Relations with Constant Coefficients Exercises

55


 2n if m=0

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


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

if

Prove that A(i, j) ≤ j whenever i and j are nonnegative


integers.
65 Suppose that f (n) is a function from the set of real
numbers, or positive real numbers, or some other set of
real numbers, to the set of real numbers such that f (n) is
monotonically increasing (that is, f (n) < f (m) when
n < m) and f (n) < n for all n in the domain of f .
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Recursively Defined Functions
4.3 Recursive Definitions and Structural Induction Recursively Defined Sets and Structures
4.4 Recursive Algorithms Structural Induction
4.5 Program Correctness Generalized Induction
4.6 Solutions to Recursive Relations with Constant Coefficients Exercises

65 The function f (k) (n) is defined recursively by


(
n, if k = 0,
f (k) (n) = (k−1)
f (f (n)), if k > 0.

The iterated function fc∗ (n) is the number of iterations of


f required to reduce its argument to c or less, so fc∗ (n) is
the smallest√nonnegative integer k such that f k (n) ≤ c.
Let f (n) = n. Find a formula for f (k) (n). What is the
value of f2∗ (n) when n is a positive integer? where fc∗ (n)
is the smallest nonnegative integer k such that f k (n) ≤ c.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

math. induction ⇐= strong induction ⇐= Recursion


How to solve a recursive relation? two solutions:
1) Let computers to compute – Algorithms;
2) compute by hand.— general formula for solutions
An algorithm is called recursive if it solves a problem by
reducing it to an instance of the same problem with smaller
input.
Give a recursive algorithm for computing n!, where n is a
nonnegative integer. Recursive relation: n! = (n − 1)!n.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Give a recursive algorithm for computing an , where a is a


nonzero real number and n is a nonnegative integer. Recursive
relation: an = a × an−1

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Devise a recursive algorithm for computing b n mod m, where


b, n, and m are integers with m ≥ 2, n ≥ 0, and 1 ≤ b < m.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Give a recursive algorithm for computing the greatest common


divisor of two nonnegative integers a and b with a < b.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Express the linear search algorithm as a recursive procedure.


Solution: To search for x in the search sequence a1 , a2 , ..., an ,
at the i th step of the algorithm, x and aj are compared. If x
equals aj , then i is the location of x. Otherwise, the search for
x is reduced to a search in a sequence with one fewer element,
namely, the sequence ai+1 , ..., an . We can now give a recursive
procedure, which is displayed as pseudocode in Algorithm 5.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Suppose we want to locate x in the sequence a1 , a2 , ..., an ,


integers in increasing order. To perform a binary search, we
begin by comparing x with the middle term, ab(n+1)/2c .
Algorithm will terminate if x equals this term. Otherwise, we
reduce the search to a smaller search sequence, namely, the
first half of the sequence if x is smaller than the middle term
of the original sequence, and the second half otherwise.
Recursive version of a binary search algorithm

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

I Prove that Algorithm 2, which computes powers of real


numbers, is correct.
I Prove that Algorithm 3, which computes modular powers,
is correct.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Sorting is done by successively merging pairs of lists. At the


first stage, pairs of individual elements are merged into lists of
length two in increasing order. Then successive merges of
pairs of lists are perfonned until the entire list is put into
increasing order. The succession of merged lists in increasing
order is represented by the balanced binary tree.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Lemma
Two sorted lists with m elements and n elements can be
merged into a sorted list using no more than m + n − 1
comparisons.
Theorem
The number of comparisons needed to merge sort a list with n
elements is O(n log2 n).
Proof. At the first stage of the splitting procedure, the list is
split into two sublists, of 2m−1 elements each, at level 1 of the
tree generated by the splitting. This process continues,
splitting the two sublists with 2m−1 elements into four sublists
of 2m−2 elements each at level 2, and so on. In general, there
are 2k−1 lists at level k − I , each with 2m−k+1 elements.
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

These lists at level k − 1 are split into 2k lists at level k, each


with 2m−k elements. At the end of this process, we have 2m
lists each with one element at level m. We start merging by
combining pairs of the 2m lists of one element into 2m−1 lists,
at level m − 1, each with two elements. To do this, 2m−1 pairs
of lists with one element each are merged. The merger of each
pair requires exactly one comparison.
Summing all estimates shows that the number of comparisons
required for the merge sort is at most
m
X m
X m
X
k−1 m−k+1 m
2 (2 − 1) = 2 − 2k−1 − m2m − (2m − 1) =
k=1 k=1 k=1

n log2 n − n + 1,
where n = 2m 
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

Exercises

No 2 (mod 10): 2, 12, 22, 32, 42, 52.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

2 Trace Algorithm 1 when it is given n = 6 as input. That


is, show all steps used by Algorithm 1 to find 6!, as is
done in Example 1 to find 4!.
12 Devise a recursive algorithm for finding x n mod m when-
ever n, x, and m are positive integers based on the fact
that x n mod m = (x n−1 mod m.x mod m) mod m.
10 Give a recursive algorithm for finding the maximum of a
finite set of integers, making use of the fact that the
maximum of n integers is the larger of the last integer in
the list and the maximum of the first n − I integers in the
list.
22 Prove that the recursive algorithm that you found in Ex-
ercise 10 is correct.
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering Proving Recursive Algorithms Correct
4.3 Recursive Definitions and Structural Induction Recursion and Iteration
4.4 Recursive Algorithms The Merge Sort
4.5 Program Correctness Exercises
4.6 Solutions to Recursive Relations with Constant Coefficients

32 Devise a recursive algorithm to find the nth term of the


sequence defined by a0 = 1, a1 = 2, a2 = 3, and
an = an−1 + an−2 + an−3 , for n = 3, 4, 5, ....
42 Give a recursive algorithm for computing values of the
Ackermann function. [Hint: See the preamble to Exercise
48 in Section 4.3.]
52 Describe the quick sort algorithm using pseudocode.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering
4.3 Recursive Definitions and Structural Induction
Exercises
4.4 Recursive Algorithms
4.5 Program Correctness
4.6 Solutions to Recursive Relations with Constant Coefficients

A program, or program segment, S is said to be partially


correct with respect to the initial assertion p and the final
assertion q if whenever p is true for the input values of S and
S terminates, then q is true for the output values of S. The
notation p{S}q (Hoare triple) indicates that the program, or
program segment, S is partially correct with respect to the
initial assertion p and the final assertion q.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering
4.3 Recursive Definitions and Structural Induction
Exercises
4.4 Recursive Algorithms
4.5 Program Correctness
4.6 Solutions to Recursive Relations with Constant Coefficients

No Exercises!

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

References

1. Logic, Mathematical Reasoning and counting


Techniques” (in Vietnamese), Statistics Publisher, 2017.
2. Rosen Book, Chapter 7, Section 7.2 Solving Linear
Recurrence Relations

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Definition A homogeneous linear recursive relation with


constant coefficients is a relation of type:

an = c1 an−1 + c2 an−2 + · · · + ck an−k ,

where c1 , c2 . . . , ck are nonzero real numbers.


Examples
1 P1 = 1, Pn = 1.084Pn−1
2 fn = fn−1 + fn−2
3 an = 2an−1 + 5an−5 are homogeneous linear recursive
relations with constant coefficients, but
4 an = an−1 + 2(an−1 )2 is nonlinear,
5 an = an−1 + 2n−2 is nonhomogeneous,
6 an = aan−1 is with nonconstant coefficients.
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Definition For the recursive relation


an = c1 an−1 + c2 an−2 + · · · + ck an−k ,
the equation
r k − c1 r k−1 − c2 r k−2 − · · · − ck−1 r − ck = 0
is called the characteristic equation
Example
1 The recursive relation from example 2 an = an−1 + an−2
has the characteristic √equation r 2 − r√− 1 = 0 which has
two solutions r1 = 1+2 5 and r2 = 1−2 5
2 The recursive relation an = 2an−2 − an−4 has its
characteristic function r 4 − 2r 2 + 1 = 0 and has two
characteristic solutions r1 = 1 and r2 = −1.
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

The 1st case k = 2.


Theorem For the recursive relation
an = c1 an−1 + c2 an−2 , n ≥ 2, c2 6= 0, if the characteristic
equation r 2 − c1 r − c2 = 0 has two distinguished solutions r1
and r2 then the sequence {an } is a solution to the recursive
relation if and only if an = α1 r1n + α2 r2n , for all n = 0, 1, . . .
with two constants α1 and α2 .
Proof. For two solutions to the recursive relation and
arbitrary α1 , α2 , substitute into the expession:
c1 an−1 + c2 an−2 = c1 (α1 r1n−1 + α2 r n−1 ) + c2 (α1 r1n−2 + α2 r n−2 )
= α1 r1n−2 (c1 r1 + c2 ) + α2 r2n−2 (c1 r2 + c2 )
= α1 r1n−2 r12 + α2 r2n−2 r22
= α1 r1n + α2 r2n = an
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Conversely, for any solution {an } to the recursive relation, we


have 
α1 + α2 = a0
α1 r1 + α2 r2 = a1
and it has solution
c1 − a0 r2 a0 r1 − a1
α1∗ = and α2∗ =
r1 − r2 r1 − r2
. The sequence {bn = α1∗ r1n + α2∗ r2n , n = 0, 1, 2 . . . } is another
solution which is equal to {an } because of uniqueness of
solution. 

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Examples
I Solve the relation an = 3an−1 − 2an−2 with initial
conditions a0 = 5, a1 = 8. Two characteristic solutions
are r1 = 1 and r2 = 2

α1 + α2 = a 0 = 5
α1 + 2α2 = a1 = 8
an = 2 + 3.2n
I Solve the Fibonacci relation fn = fn−1 + fn−2 .
√ √
1+ 5 1− 5
r1 = and r2 =
2 2
√ !n √ !n
1+ 5 1− 5
fn = α 1 + α2
2 2
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients


√1
α + α 2 √ = f0 = 0
α1 1+2 5 + α2 1−2 5 = f1 = 1
Therefore we have α1 = √1 and α2 = − √15
5

√ !n √ !n
1 1+ 5 1 1− 5
fn = √ −√
5 2 5 2

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

The 2nd case: k = 2, double characteristic root .


Theorem For the recursive relation
an = c1 an−1 + c2 an−2 , n ≥ 2, c2 6= 0, if the characteristic
equation r 2 − c1 r − c2 = 0 has two double solution
r0 = r1 = r2 then the sequence {an } is a solution to the
recursive relation if and only if an = α1 r0n + α2 nr0n , for all
n = 0, 1, . . . with two constants α1 and α2 .
Proof. For double solution r0 to the recursive relation and
arbitrary α1 , α2 , substitute into the expession:
c1 an−1 + c2 an−2 = c1 (α1 r0n−1 + α2 (n − 1)r0n−1 ) + c2 (α1 r0n−2 + α2 (n
= α1 r0n−2 (c1 r0 + c2 ) + α2 r0n−2 (c1 r0 + c2 )
= α1 r0n−2 r02 + α2 nr0n−2 r02
= α1 r0n + α2 nr0n = an
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Conversely, for any solution {an } to the recursive relation, we


have 
α1 = a0
α1 r0 + α2 r0 = a1
and it has solution
a1
α1∗ = a0 and α2∗ =
r0
. The sequence {an = α1∗ r0n + α2∗ nr0n , n = 0, 1, 2 . . . } is another
solution which is equal to {an } because of uniqueness of
solution. 

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Solve the recursive relation an = −4an−1 − 4an−2 with initial


values a0 = 1 and a1 = 4. The characteristic equation is
r 2 + 4r + 4 = 0 The double characteristic root is r = −2
Recursive solution is an = α1 (−2)n + α2 n(−2)n where α1 and
α2 are constants.

a0 = 1 = α1
a1 = 4 = α1 (−2) + α2 (−2)

Therefore α1 = 1 and α2 = −3.

an = (−2)n − 3n(−2)n

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

The 3rd case: k = 2, no characteristic root.

Theorem For the recursive relation


an = c1 an−1 + c2 an−1 , n ≥ 2, c2 6= 0, if the characteristic
equation r 2 − c1 r − c2 = 0 has no real solution
∆ = c12 + 4c2 < 0 then the sequence {an } is a solution to the
recursive relation if and only if an = ρn (α1 cos nθ + α2 sin nθ),
for all n = 1, . . . with two constants α√1 and α2 , and
√ c |∆|
ρ = −∆, cos θ = 2√−c 1
2
or sin θ = 2√−c2 .

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Example Solve the recursive an = an−1 − an−2 with


p relation √
a0 = 1 and a1 = 1. ρ = −(−3) = √ 3 choose 0 ≤ θ ≤ 2π
such that cos θ = 1/2 and sin θ = 3/2 or α = π/3.
√ n nπ nπ
an = 3 (cos + α2 sin )
3 3
and 
a0 = 1 = α1 ,
a1 = 1 = α1 cos π3 + α2 sin π3 .

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Definition A nonhomogeneous linear recursive relation is a


relation of type:
an = c1 an−1 + c2 an−2 + · · · + ck an−k + F (n)
where c1 , . . . , ck are constants and ck 6= 0.
Examples an = 2an−1 + 2n .
Theorem Given a recursive relation
an = c1 an−1 + · · · + ck an−k + F (n).
If {pn } is a solution of the relation then any solution is of form
{pn + hn } where {hn } is an arbitrary solution of the
homogeneous relation
an = c1 an−1 + · · · + ck an−k
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Proof. For an arbitrary solution {qn } of the nonhomogeneous


recursive relation,

qn = c1 qn−1 + c2 qn−2 + · · · + ck qn−k + F (n)

and we have

pn = c1 pn−1 + c2 pn−2 + · · · + ck pn−k + F (n).

Therefore,

hn = qn −pn = c1 (qn−1 −p n−1 )+c2 (qn−2 −pn−2 )+· · ·+ck (qn−k −pn−k )

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Case 1.
a. F (n) = b0 nm + · · · + bm If the characteristic equation
r k − c1 r k−1 − · · · − ck = 0 does not admit r = 1 as a root
then we find roots of form p = t0 nm + t1 nm−1 + · · · + tm ,
where t0 , . . . , tm are finding by the method of undeterminated
coefficients.
Examples Find a particular solution of the recursive relation
an = an−1 + 2an−2 + n + 1. The characteristic equation is
r 2 − r − 2 = 0 has no solution r = 1. Find a particular solution
of form pn = bn + c. Substitute into the equation we have
bn + c = [b(n − 1) + c] + 2[b(n − 2) + c] + n + 1
2b + 1 = c
−5b + 2c + 1 = 0
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Examples
1 b = − 21 and c = 34 . The particular solution is of form
−1 3
pn = n+ .
2 4
b. The characteristic equation has multiple solution r = 1
of multiple s, then find a particular solution
pn = ns (t0 nm + t1 nm−1 + · · · + tm ).
2 Find a particular solution of the recursive relation
an = 3an−1 − 2an−3 + 1. Find a particular solution of the
form pn = an2 and sutstitute into the equation, we have
an2 = 3a(n − 2)2 − 2a(n − 3)2 + 1 = an2 − 6a + 1
n2
−6a + 1 = 0 or a = 1/6, pn = 6
.
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Case 2. F (n) = Aβ n
a If characteristic roots are different from β, then find a
particular solution pn = αβ n .
b If there is a characteristic roots r = β of multiplicity s
then find a particular solution of form pn = ans β n
Example
a Find a particular solution of an = an−2 + 2n . The
characteristic equation r 2 − 1 = 0 has solution
r = ±1 6= 2, we find pn = a2m . Substitute into equation
we have
a2m = a2m−1 + 2m ,
then a = 43 , pn = 43 2n .
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Case 3.
F (n) = (b0nm + b1nm−1 + · · · + bm ) + Aβ n .

Find the particular solution pn = pn1 + pn2 as sum of two


particular solutions for the cases 1 and 2 respectively.
Example Find a particular solution of the relation
an = 6an−1 + 3n + 5n Particular solution to an = 6an−1 + 3n is
pn1 = −3n . Particular solution to an = 6an−1 + 5n is
pn2 = −n − 56 Then the particular solution
pn = pn1 + pn2 = −3n − n − 56

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Due date: 2 weeks

Exercises page 156- 164. “Logic, Mathematical Reasoning and


counting Techniques” (in Vietnamese), Statistics Publisher,
2017. No 4.3, 4.5, 4.6, 4.11, 4.13, 4.33, 4.37

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Exercise
4.3 Give a recursive definition of sequences {an }, n = 1, 2, . . .
a. an = 5 e. an = 1 + (−1)n
b. an = 6n f. an = 10n
c. an = 2n + 1 g. an = 5n + (−1)n−1
d. an = n(n + 1) h. an = (−4)n + 3n − 1
4.5 Find a recursive relation for number sequences
r

q
1
a. an = 2 + 2 + · · · + 2 b. bn = 2 + 1
| {z } 2 + ...2+ 1
2
n times | {z }
n times

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Exercises
4.6 Give a defini-
tion of Fibonacci sequence. Prove the following properties:
a. f12 + f22 + . . . fn2 = fn fn+1 d. fn+1 dn−1 − fn2 = (−1)n
b. f1 + f2 + · · · + fn = fn+2 − 1 e. f0 f1 + f1 f2 + · · · +
2
+f2n−1 f2n = f2n
c. f1 + f3 + · · · + f2n−1 = f2n f. f0 − f1 + f2 − . . .
−f2n−1 + f2n = f2n−1 − 1
4.11 For any of the following sequences find at least one
recursive relation:
a. an = 3, n ≥ 0 e. an = n2 , n ≥ 0
n
b. an = 2 , n ≥ 0 f. an = n3 + n, n ≥ 0
c. an = 2n + 3, n ≥ 0 g. an = n + (−1)n , n ≥ 0
d. an = 5n , n ≥ 0 h. an = n!, n ≥ 0.
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Exercises
4.13 Somebody invested VND 10,000 into his bank account at
a bank with annual rate of 10%.
a Establish a recursive relation for the amount of money in
the account at the end of nth year.
b Find the exact formula for the amount at the end of nth
year.
c How much will be the amount of money after 20 years.
4.33 State the rule for solving the homogeneous linear
recursive relations in cases the characteristic equation has:
3 distinguished roots, one root of multiple 2, one root of
multiple 3. Find solutions of the following relations:
a an = 2dn−1 + an−2 − 2an−3 , for
n ≥ 3, a0 = 3, a1 = 6, a2 = 0.
b an = an−2 + 6an−3 , for n ≥ 3, a0 = 9, a1 = 10, a2 = 32.
Do Ngoc Diep Chapter 4. Induction and Recursion
4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

Exercises
4.33 c an = 4an−1 − 5an−2 + 2an−3 , for
n ≥ 3, a0 = 0, a1 = 1, a2 = 2.
4.37 Find solutions of the following recursive relations:
a an = 3an−1 + 2n , for n ≥ 1, a0 = 1.
b an = 3an−1 − 2an−2 + 5, for n ≥ 2, a0 = 1, a1 = 3.
f an = 7an−2 − 6an−3 + 1 + (−3)n , for
n ≥ 3, a0 = −2, a1 = −6, a2 = 35.

Do Ngoc Diep Chapter 4. Induction and Recursion


4.1 Mathematical Induction
4.2 Strong Induction and Well-Ordering 4.6.1. Linear Recursive Relations
4.3 Recursive Definitions and Structural Induction 4.6.2. Solving Homogeneous Linear Recursive Relations of degree
4.4 Recursive Algorithms 4.6.3. Nonhomogeneous Linear Recursive Relation
4.5 Program Correctness Exercise
4.6 Solutions to Recursive Relations with Constant Coefficients

To be Training

I Key Terms and Results


I Review Questions
I Supplementary Exercises

Do Ngoc Diep Chapter 4. Induction and Recursion

You might also like