Professional Documents
Culture Documents
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
Do Ngoc Diep
Discussion
Principle of Induction
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 2n < n!
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
Exercises
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
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.
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.
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
Exercises
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.
Recursive Picture
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 = 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
Structural Induction
Generalized Induction
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
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
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 Exercises!
References
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
an = (−2)n − 3n(−2)n
and we have
Therefore,
hn = qn −pn = c1 (qn−1 −p n−1 )+c2 (qn−2 −pn−2 )+· · ·+ck (qn−k −pn−k )
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 .
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
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.
To be Training