Mth1114 Induction Andrecursion MINE
Mth1114 Induction Andrecursion MINE
Mth1114 Induction Andrecursion MINE
Computer
Mathematics
Week10
Mathematical Induction &
Recursion
Mathematical Induction
2
Induction
The principle of mathematical induction is a
useful tool for proving that a certain predicate is
true for all natural numbers.
3
Induction
If we have a propositional function P(n), and we
want to prove that P(n) is true for any natural
number n, we do the following:
4
Induction
Example:
5
Induction
2. Show that if P(n) is true, then P(n + 1) is true.
(inductive step)
6
Induction
3. Then P(n) must be true for any positive
integer.
(conclusion)
End of proof.
7
Induction
Another Example (“Gauss”):
1 + 2 + … + n = n (n + 1)/2
8
Induction
2. Show that if P(n) then P(n + 1) for any nN.
(inductive step)
1 + 2 + … + n = n (n + 1)/2
1 + 2 + … + n + (n + 1) = n (n + 1)/2 + (n + 1)
= (n + 1) (n/2 + 1)
= (n + 1) (n + 2)/2
= (n + 1) ((n + 1) + 1)/2
9
Induction
End of proof.
10
Induction
There is another proof technique that is very similar
to the principle of mathematical induction.
11
Induction
The second principle of mathematical induction:
12
Induction
Example:
Show that every integer greater than 1 can be
written as the product of primes.
13
Induction
• Show that if P(2) and P(3) and … and P(n),
then P(n + 1) for any nN. (inductive step)
Two possible cases:
• If (n + 1) is prime, then obviously P(n + 1) is true.
• If (n + 1) is composite, it can be written as the
product of two integers a and b such that
2 a b < n + 1.
By the induction hypothesis, both a and b can be
written as the product of primes.
Therefore, n + 1 = ab can be written as the product
of primes.
14
Induction
End of proof.
15
Another Induction Example
Show that the sum of the first n odd integers is n2
– Example: If n = 5, 1+3+5+7+9 = 25 = 52
– Formally, Show n P(n) where P(n) = ni=1(2i -1) = n2
3 divides k 3 + 2k + 3(k 2 + k + 1)
3 divides (k + 1) + 2(k + 1)
3
20
Recursive Definitions
Recursion is a principle closely related to
mathematical induction.
21
Recursively Defined Sequences
Example:
a0 = 1
an+1 = 2an for n = 0, 1, 2, …
23
Recursively Defined Functions
Example:
f(0) = 3
f(n + 1) = 2f(n) + 3
f(0) = 3
f(1) = 2f(0) + 3 = 23 + 3 = 9
f(2) = 2f(1) + 3 = 29 + 3 = 21
f(3) = 2f(2) + 3 = 221 + 3 = 45
f(4) = 2f(3) + 3 = 245 + 3 = 93
24
Recursively Defined Functions
How can we recursively define the factorial
function f(n) = n! ?
f(0) = 1
f(n + 1) = (n + 1)f(n)
f(0) = 1
f(1) = 1f(0) = 11 = 1
f(2) = 2f(1) = 21 = 2
f(3) = 3f(2) = 32 = 6
f(4) = 4f(3) = 46 = 24
25
Recursively Defined Functions
A famous example: The Fibonacci numbers
f(0) = 0, f(1) = 1
f(n) = f(n – 1) + f(n - 2)
f(0) = 0
f(1) = 1
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
f(6) = f(5) + f(4) = 5 + 3 = 8
26
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.
27
Recursive Algorithms
Example II: Recursive Fibonacci Algorithm
29
Recursive Algorithms
30