�Discrete Mathematics (MAD101)
Chapter 4:
Induction & Recursion
4. 1 Mathematical Induction
Let P(n) be a propositional function. To prove that P(n) is true, for all n ≥ 0
We need to do 2 steps:
Assume that P(k) is true (induction hypothesis)
Prove that P(k+1) is also true.
4. 1 Mathematical Induction
1+ 3+ 5+...+ (2n-1) = n² , for all n ≥ 1
Proof: Let P(n): 1+ 3+ 5+...+ (2n-1) = n²
Indeed, to prove P(k+1) is true, we compute
1+ 3+ 5+...+ (2(k+1)-1)= 1+ 3+ 5+...+ (2k-1) + (2(k+1)-1)
By induction hypothesis, P(k) is true, meaning that 1+ 3+ 5+...+ (2k-1) = k². So
1+ 3+ 5+...+ (2(k+1)-1) = k² +(2(k+1)-1) = k² +2k +1 =(k+1)².
Hence P(k+1) is also true.
4. 1 Mathematical Induction
n³- n is divisible by 3, for all n ≥ 0
4. 1 Mathematical Induction
4. 2 Strong Induction
Let P(n) be a propositional function. To prove that P(n) is true, for all n ≥ 0
We need to do 2 steps:
Assume that P(0), P(1), …, P(k) are all true (induction hypothesis)
Prove that P(k+1) is also true.
4. 2 Strong Induction
a₀=1 , a₁= 3 , aₙ₊₁= 2aₙ -aₙ₋₁ , ∀n ≥ 1.
Prove that ∀n ≥ 0, aₙ= 2n+1.
Proof:
4. 2 Strong Induction
a₀=1 , a₁= 3 , aₙ₊₁= 2aₙ -aₙ₋₁ , ∀n ≥ 1.
Prove that ∀n ≥ 0, aₙ= 2n+1.
Proof:
n=0, a₀=1 = 2.0 +1 (true)
n= 1, a₁= 3 = 2.1 +1 (true)
We prove that aₖ₊₁= 2(k+1)+1.
Indeed, by inductive hypothesis: aₖ = 2.k +1 and aₖ₋₁= 2.(k-1)+1, so
aₖ₊₁= 2aₖ -aₖ₋₁ = 2.(2k+1)- (2.(k-1) +1) =2k+ 3= 2(k+1) +1.
∀n ≥ 1, aₙ= 2n+1.
4. 2 Strong Induction
Let (fₙ) be sequence that is defined as followed:
f₀= 0, f₁=1 fₙ₊₁ = fₙ +fₙ₋₁
Prove that for all n ≥ 2,
4. 2 Strong Induction
Proof: We use strong induction
4. 2 Strong Induction
Proof: We use strong induction
n= 12= 4.3, so n can be changed using 4 coins 3
n= 13 = 2.5 +1.3, so n can be changed using 2 coins 5 and 1 coin 3
n= 14= 1.5 +3.3, so n can be changed using 1 coin 5 and 3 coins 3
k+1= 3+(k-2)
Now, since 14 ≤ k, 12 ≤ (k-2) <k , by induction hypothesis (k-2) can be changed : (k-2)= x.3 +y.3
This implies: k+1 = 3+ (k-2) = 3+ x.3 +y.5 =(x+1).3 + y.5, so (k+1) can be changed using (x+1) coins 3 and y coins 5.
Conclusion: By induction principle, there is always possible to change any amount of n ≥ 12 using 2 coins of values 3 and 5 !
4. 2 Strong Induction
(k+1)= 3+(k-2).
so, to be able to use induction hypothesis, k-2 must be greater than or equal to 12, which means k ≥ 14. That is why n= 12,13, 14 are initial values !
Question: How many initial values for which we need to check at the Basic step if we write (k+1)= 5 +(k-4) ?
4. 1 Mathematical Induction
4.3 Recursive Definition
Use:
Find f(1), f(2),..., f(4), and f(n) ?
4.3 Recursive Definition
Answer:
to determine a recursive relation for xₙ, note that:
xₙ= 6. 11ⁿ= 6. 11ⁿ⁻¹ .11 =11.xₙ₋₁, so a recursive definition for the sequence xₙ is
x₀=6 and xₙ = 11.xₙ₋₁ for n ≥ 1
y₀=1 and yₙ = - yₙ₋₁ for n ≥ 1
zₙ = 1+2+3+...(n-1)+ n and zₙ₋₁= 1+2+3+...+(n-1), so
zₙ - zₙ₋₁ = (1+2+3+...(n-1)+ n) - (1+2+3+...+(n-1))= n, which implies zₙ = zₙ₋₁ +n
recursive definition for zₙ is : z₁ = 1 (initial value) and zₙ = zₙ₋₁ +n (n > 1)
4.3 Recursive Definition
Answer:
The recursive idea helps to reduce the input n to lower and lower inputs :
f(n)= 2f(n-1)+1
= 2 [2.f(n-2)+1] +1 = 2²f(n-2) +2 +1
= 2²[2.f(n-3) +1]+2 +1 = 2³f(n-3) +2² +2 +1
= …
= 2ⁿ.f(0) +2ⁿ⁻¹ + 2ⁿ⁻² +...+ 2 +1
= 2ⁿ +2ⁿ⁻¹ + 2ⁿ⁻² +...+ 2 +1 = (2ⁿ⁺¹ - 1)/(2-1) = 2ⁿ⁺¹ - 1
Conclusion: general formula for f(n) is f(n)= 2ⁿ⁺¹ - 1 (n ≥ 0).
Recall:
rⁿ +r ⁿ⁻¹+...+r+ 1 = (rⁿ⁺¹ -1)/ (r-1)
( r≠ 1)
4.3 Recursive Definition
4.3 Recursively Defined Sets
S= {3,6, 9, 12….}= the set of all positive multiples of 3
4.3 Recursively Defined Sets
4.3 Recursively Defined Sets
Answer:
Recursive step: If x ∈ S, then (x+3) ∈ S and (x-3) ∈ S.
Recursive step: If x ∈ S, then (x+3) ∈ S.
4.3 Recursively Defined Sets
The set ∑* of strings over ∑ can be defined recursively
Example: ∑= {0,1}
4.4 Structural Induction (quy nạp tổng quát)
Induction Structure: Proving properties for recursively defined sets
Recursive definition of a set provides an order/structure on this set, so that we can use induction principle:
To prove a property (P) is true for all elements of a recursively defined set (S):
Assume that an element x ∈ S has property (P) // giả sử phần tử x ∈ S có tính
chất (P)
Prove that the next element (the element generated by x) also has property (P)
// chứng minh phần tử tiếp theo (phần tử “sinh" ra bởi x) cũng có tính chất (P)
4.4 Structural Induction (quy nạp tổng quát)
Induction Structure: Proving properties for recursively defined sets
Show that for any element x ∈ S, x is not divisible by 3
4.4 Structural Induction (quy nạp tổng quát)
Induction Structure: Proving properties for recursively defined sets
Show that for any element x ∈ S, x is not divisible by 3
Answer:
By induction principle, we conclude that for any x ∈ S, x is not divisible by 3 !
4.4 Structural Induction (quy nạp tổng quát)
Induction Structure: Proving properties for recursively defined sets
4.4 Structural Induction (quy nạp tổng quát)
Induction Structure: Proving properties for recursively defined sets
Basis step: 5 ∈ S.
Recursive step: If n∈S, then 3n∈ S and n² ∈S.
4.4 Structural Induction (quy nạp tổng quát)
Induction over pairs of integers
4.5 Structural Induction
QUIZ
What is S ?
2. The sequence g(n) is defined as follows
g(0)=0 , g(1)= 1, g(n+1)= g(n) +g(n-1) (mod 3)
Find g(6) ? A. 8 B. 2 C. 3 D. 4
4.5 Structural Induction
QUIZ
3. What can be the recursive definition of the set S of all even positive integers?
4. Let a₁,₁ = 5 and
What is the general formula of aₘ,ₙ
4.5 Structural Induction
QUIZ
5. Does this recursive definition produce a well-defined function on N?
F(n)=1+F(n−2) for n≥2 and F(1)=0.
4.5 Recursive Algorithm
(nguồn: runestone.academy)
4.5 Recursive Algorithm
Procedure factorial( n: non-negative integer)
If n=1 then return 1
Else return n. factorial (n-1)
Example: 4! = 4. 3! = 4. 3. 2! = 4.3. 2. 1! = 4.3.2.1 = 24.
4.5 Recursive Algorithm
b) Euclid algorithm
procedure gcd(a ≥ b: positive integers)
if b=0, then return a
else return gcd(b, a mod b)
{ output is gcd(a,b) }
Question:
Compute gcd(36,14).
What is the base case ?
Which recursive relation is used ?
Example: Compute the Fibonacci sequence
Using function calls Using loops
(+): easy to understand, easy for implementation (+) require less computations than recursive one
(-) require more computations than iterative one (-) may become tricky and hard to interpret
Which algorithm is recursive, iterative ?
Procedure ModExp(a, n, m): result = 1 a = a mod m while n > 0: if n is odd: result = (result * a) mod m a = (a * a) mod m n = n // 2 return result | Procedure mpower (b, n, m, integers, b>0,m ≥ 2, n ≥ 0) if n= 0 then return 1 else if n is even then return mpower (b, n/2, m)² mod m else return (mpower (b, ⌊n/2⌋, m)² mod m). (b mod m) mod m {output is bⁿ mod m } |
4.5 Recursive Algorithm
4.5 Recursive Algorithm
Review:
procedure bubble sort (a1,a2,…,an :real numbers with n ≥ 2)
for i:= 1 to n-1
for j:=1 to n- i
if aj > aj+1 then interchange aj and aj+1
{a1,a2,…,an are sorted}
worst case: how many comparisons ?
(n-1)+(n-2)+...+1+0= n(n-1)/2 comparisons ~ O(n^2)
(similarly for Insertion Sort) ~ O(n^2)
4.5 Recursive Algorithm
Bước 1: Chia L thành 2 dãy con (phân đôi)
4.5 Recursive Algorithm
Bước 2: sắp xếp gộp lại
Idea: to merge two sorted lists, T and U, into a single sorted list, we compare the first elements of two lists at each step and place the smaller of the two items we are viewing into the output list L.
4.5 Recursive Algorithm
Example: To merge 2 list {2, 3, 5, 6} and {1, 4}
Step | First list | Second list | Comparison | L |
1 | 2, 3, 5, 6 | 1, 4 | 2 >1 | 1 |
2 | 2, 3, 5, 4 | 4 | 2 <4 | 1, 2 |
3 | 3, 5, 6 | 4 | 3 < 4 | 1, 2, 3 |
4 | 5, 6 | 4 | 5> 4 | 1, 2, 3, 4, 5, 6 |
4.5 Recursive Algorithm
Question: How many comparisons needed?
4.5 Recursive Algorithm
The number of comparisons performed by the algorithm MergeSort for an input list of length n is O(n.log₂(n)).