Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
98 views

Chapter5 - Induction and Recursion

This document summarizes Chapter 5 on induction and recursion. It covers mathematical induction, strong induction, recursive definitions, recursive algorithms, and proving recursive algorithms correct. Examples are provided for each topic, such as using induction to prove properties of sums and factorials, recursively defining sets and strings, and recursive algorithms for computing factorials, greatest common divisors, and searching/sorting lists. Exercises are listed at the end related to each section.

Uploaded by

Dao Xuan Dat
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views

Chapter5 - Induction and Recursion

This document summarizes Chapter 5 on induction and recursion. It covers mathematical induction, strong induction, recursive definitions, recursive algorithms, and proving recursive algorithms correct. Examples are provided for each topic, such as using induction to prove properties of sums and factorials, recursively defining sets and strings, and recursive algorithms for computing factorials, greatest common divisors, and searching/sorting lists. Exercises are listed at the end related to each section.

Uploaded by

Dao Xuan Dat
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Chapter 5: Induction and Recursion

Nguyen Thi Minh Tam


tamntm16@fe.edu.vn

June 22, 2020


1 5.1 Mathematical Induction

2 5.2 Strong Induction and Well-Ordering

3 5.3 Recursive Definitions and Structural Induction

4 5.4 Recursive Algorithms


5.1 Mathematical Induction
5.2 Strong Induction and Well-Ordering
5.3 Recursive Definitions and Structural Induction
5.4 Recursive Algorithms

5.1 Mathematical Induction

3/27
Principle of Mathematical Induction
To prove that P(n) is true for all positive integers n, where P(n) is
a propositional function, we complete two steps:
Basic step: Verify P(1) is true
Inductive step: Show that if P(k) is true, then P(k + 1) is
true for all positive integers k.

Example 1. Show that if n is a positive integer, then

n(n + 1)
1 + 2 + ... + n = .
2
Example 2. Conjecture a formula for the sum of the first n
positive odd integers. Then prove your conjecture using
mathematical induction.

Example 3. Use mathematical induction to prove the inequality

2n < n!

for all integers n ≥ 4.

Example 4. Use mathematical induction to prove that n3 − n is


divisible by 3 whenever n is a positive integer.
5.1 Mathematical Induction
5.2 Strong Induction and Well-Ordering
5.3 Recursive Definitions and Structural Induction
5.4 Recursive Algorithms

5.2 Strong Induction and Well-Ordering

Principle of 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:
Basic step: Verify P(1) is true
Inductive step: Show that if P(j) is true for j = 1, 2, . . . , k,
then P(k + 1) is true for all positive integers k.

6/27
Example 5. Show that if n is an integer greater than 1, then n
can be written as the product of primes.

Example 6. Prove that every amount of postage of 12 cents or


more can be formed using just 4-cent and 5-cent stamps.
Using Strong Induction in Computational Geometry

Polygon
A polygon is a closed geometric figure consisting of a
sequence of line segments s1 , s2 , . . . , sn , called sides.
Each pair of consecutive sides of the polygon meet at a
common endpoint, called a vertex.
A polygon is called simple if no two nonconsecutive sides
intersect.
Every simple polygon divides the plane into two regions: its
interior, consisting of the points inside the curve, and its
exterior, consisting of the points outside the curve.
Diagonal
A diagonal of a simple polygon is a line segment connecting
two nonconsecutive vertices of the polygon.
A diagonal is called an interior diagonal if it lies entirely inside
the polygon, except for its endpoints.
Theorem 1
A simple polygon with n sides, where n is an integer with n ≥ 3,
can be triangulated into n − 2 triangles.
Lemma 1
Every simple polygon with at least four sides has an interior
diagonal.
5.1 Mathematical Induction
5.2 Strong Induction and Well-Ordering
5.3 Recursive Definitions and Structural Induction
5.4 Recursive Algorithms

5.3 Recursive Definitions and Structural Induction

Sometimes it is difficult to define an object explicitly.


However, it may be easy to define this object in terms of
itself. This process is called recursion.

Recursively Defined Functions


We use two steps to define a function with the set of nonnegative
integers as its domain:
Basic 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.

12/27
Example 7. Suppose that f is defined recursively by

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

Find f (4).

Example 8. Suppose that f is defined recursively by

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

Find f (16).
Fibonacci numbers

f (0) = 0, f (1) = 1
f (n) = f (n − 1) + f (n − 2), n = 2, 3, . . .

Lamé’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.
Recursive Definitions of Sets
Basic step: Specify an initial collection of elements.
Recursive step: Give a rule for forming new elements in the
set from those already known to be in the set.

Example 9. Consider the subset S of the set of integers


recursively defined by
Basic step: 3 ∈ S.
Recursive step: If x ∈ S and y ∈ S, then x + y ∈ S.
The Set of Strings over Σ
The set Σ∗ of strings over the alphabet Σ is defined recursively by
Basic step: λ ∈ Σ∗ (where λ is the empty string containing
no symbols).
Recursive step: If w ∈ Σ∗ and x ∈ Σ, then wx ∈ Σ∗ .

Example 10. If Σ = {0, 1}, then Σ∗ is the set of all bit strings.
The Concatenation of Two Strings
Basic step: If w ∈ Σ∗ , then w · λ = w , where λ is the empty
string.
Recursive step: If w1 , w2 ∈ Σ∗ and x ∈ Σ, then
w1 · (w2 x) = (w1 · w2 )x ∈ Σ∗ .
5.1 Mathematical Induction
5.2 Strong Induction and Well-Ordering
5.3 Recursive Definitions and Structural Induction
5.4 Recursive Algorithms

An algorithm is called recursive if it solves a problem by reducing it


to an instance of the same problem with smaller input.

Example 11. Recursive algorithm for computing n!

18/27
Example 12. Recursive algorithm for computing an

Example 13. Recursive algorithm for computing gcd(a, b)


Example 14. 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.

If n is even: b n = b n/2 · b n/2


⇒b n mod m = ((b n/2 mod m) · (b n/2 mod m)) mod m
⇒b n mod m = (b n/2 mod m)2 mod m

If n is odd: b n = b · b bn/2c · b bn/2c


 
⇒b n mod m = ((b bn/2c mod m)2 mod m) · (b mod m) mod m
Recursive algorithm for computing b n mod m
Example 15. Express the linear search algorithm as a recursive
procedure.
Let search(i, j, x) be the procedure that searches for the first
occurrence of x in the sequence ai , ai+1 , . . . , aj .
The input to the procedure consists of the triple (1, n, x).
Example 16. Recursive version of a binary search algorithm
Proving Recursive Algorithms Correct

Mathematical induction, and its variant strong induction, can be


used to prove that a recursive algorithm is correct

Example 17. Prove that the recursive algorithm for computing


n!, is correct.
Recursion and Iteration
Recursive algorithm for finding the nth Fibonacci number
Iterative algorithm for finding the nth Fibonacci number

A recursive algorithm may require far more computation than an


iterative one.
The Merge Sort
Recursive merge sort algorithm
Algorithm for merging two lists
Exercises

Section 5.1 3, 19, 21, 34 (page 329, 330)


Section 5.2 3, 25 (page 341, 342)
Section 5.3 1, 3, 5, 7, 9, 25, 27ab (page 357, 358)
Section 5.4 1, 3, 5, 9, 44 (page 370, 371)

You might also like