04-Induction and Recursion
04-Induction and Recursion
Introduction
Mathematical Induction
Examples of Proofs by Mathematical
Induction
Principle of
Mathematical
Induction
Principle of Mathematical Induction
To prove P(n) is true for all positive
integers n, where P(n) is a propositional
function, we complete two step:
Basic step:
Verifying P(1) is true
Inductive step:
Assume that P(k) is true for some positive
integer k.
Prove that P(k + 1) is true.
Conclusion: P(n) is true for all positive
integers n
Induction: Example 1
Theorem 1:
A simple polygon with n sides, where n is
integer with n ≥ 3, can be triangulated into n-2
triangles
f (n 1) f (n 2), n 1
Theorem 1: Lamé’s theorem: Let a,b be integers, 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: page 348
Example gcd(25,7), b= 7 , 1 digit
x y r
25 7 25 mod 7=4 procedure gcd(a,b)
7 4 7 mod 4=3 x:=a; y:=b
4 3 4 mod 3=1 while y 0
3 1 3 mod 1=0 ( 4 divisions) begin
r := x mod y
1 0 Stop
x:=y
y:= r
end { gcd(a,b) is x}
Recursively Defined Sets and Structures
n!= 1 , n=0
n!= 1.2.3.4…n = n.(n-1)!, n>0
Recursive Algorithms…
an= 1 , n=0
an= a.a.a…a = a.an-1, n>0
Recursive Algorithms…
Page: 362
Recursive Algorithms…
i>j location =0
ai=x location = i
location (i, j, x) = location ( i+1, j, x)
Procedure mergeSort (
L=a1…an)
If n>1 then
Begin Merge?
m:= n/2
L1 := a1…am
L2 := am+1…an
L:=merge(mergeSort(L1),mergeSort(L2))
End
{L is sorted}
L1: 1 2 2 5 7 9 12 15 17 19 L2: 3 5 8 9 11 15
Merge Sort
≤ L : 1 2 2 3 5 5 7 8 9 9 11 12 15 15 17 19