Chapter # 5 : Induction and...

23
ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014 ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 1 / 23

Transcript of Chapter # 5 : Induction and...

Page 1: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

ECOM 2311- Discrete Mathematics

Chapter # 5 : Induction and Recursion

Fall, 2013/2014

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 1 / 23

Page 2: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Outline

1 Mathematical Induction

2 Strong Induction and Well-Ordering

3 Recursive Definitions

4 Recursive Algorithms

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 2 / 23

Page 3: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Mathematical InductionIntroduction

PRINCIPLE OF MATHEMATICAL INDUCTION

To prove that P(n) is true for all positive integers n, where P(n) is apropositional function, we complete two steps:BASIS STEP: We verify that P(1) is true.INDUCTIVE STEP: We show that the conditional statementP(k)→ P(k + 1) is true for all positive integers k.

Expressed as a rule of inference, this proof technique can be statedas (P(1) ∧ ∀k(P(k)→ P(k + 1)))→ ∀nP(n).

The steps of the mathematical induction proof:

Show that P(1) is true.Show that P(k)→ P(k + 1) is true for every positive integer k. Toprove that this conditional statement is true for every positive integerk, we need to show that P(k + 1) cannot be false when P(k) is true.This can be accomplished by assuming that P(k) is true and showingthat under this hypothesis P(k + 1) must also be true.

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 3 / 23

Page 4: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Mathematical InductionExamples

Example: Show that if n is a positive integer, then1 + 2 + · · ·+ n = n(n+1)

2

We must do two things to prove that P(n) is true for n = 1, 2, 3, · · ·Namely,we must show that P(1) is true and that the conditionalstatement P(k) implies P(k + 1) is true for k = 1, 2, 3, · · · .BASIS STEP: P(1) is true, because 1 = 1·(1+1)

2

INDUCTIVE STEP: For the inductive hypothesis we assume thatP(k) holds for an arbitrary positive integer k. That is, we assume

that 1 + 2 + · · ·+ k = k(k+1)2

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 4 / 23

Page 5: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Mathematical InductionExamples

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 5 / 23

Page 6: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Mathematical InductionExamples

Example: Use mathematical induction to show that1 + 2 + 22 + · · ·+ 2n = 2n+1 − 1 for n = 0, 1, 2, · · ·

Let P(n) be the proposition that 1 + 2 + 22 + · · ·+ 2n = 2n+1 − 1for the integer n.

BASIS STEP: P(0) is true because 20 = 1 = 21 − 1.

INDUCTIVE STEP: For the inductive hypothesis we assume thatP(k) holds for an arbitrary nonnegative integer k. That is, weassume that 1 + 2 + 22 + + 2k = 2(k+1) − 1

We need to prove that1 + 2 + 22 + + 2k + 2(k+1) = 2(k+1)+1 − 1 = 2(k+2) − 1.

Given the hypothesis p(k)., we see that

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 6 / 23

Page 7: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Mathematical InductionExamples

Example: Use mathematical induction to show that n < 2n for allpositive integers n

Let P(n) be the proposition that n < 2n for the positive integer n.

BASIS STEP: P(1) is true because 1 < 21 = 2.

INDUCTIVE STEP: For the inductive hypothesis we assume thatP(k) holds for an arbitrary positive integer k. That is, we assumethat k < 2k

We need to prove that k + 1 < 2k+1.

Given the hypothesis p(k)., we see thatk + 1 < 2k + 1 ≤ 2k + 1 ≤ 2k + 2k = 2 · 2k = 2k+1.

Exercise:Use mathematical induction to prove that 2n < n! for every integer nwith n ≥ 4.

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 7 / 23

Page 8: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Mathematical InductionExamples

Example: Use mathematical induction to prove that n3 − n is divisibleby 3 whenever n is a positive integer.

Let P(n) be the proposition that ”n3 − n is divisible by 3” for thepositive integer n.

BASIS STEP: P(1) is true because 13 − 1 = 0 is divisible by 3.

INDUCTIVE STEP: For the inductive hypothesis we assume thatP(k) holds for an arbitrary positive integer k. That is, we assumethat k3 − k is divisible by 3.

We need to prove that (k + 1)3 − (k + 1) is divisible by 3.

(k+1)3−(k+1) = (k3+3k2+3k+1)−(k+1) = (k3−k)+3(k2+k).

The first term is divisible by 3 form the hypothesis and the secondterm is a multiple of 3 and hence is divisible by 3. Accordingly,(k3 − k) + 3(k2 + k) is divisible by 3.

Exercise: Use mathematical induction to prove that 7n+2 + 82n+1 isdivisible by 57 for every nonnegative integer n.

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 8 / 23

Page 9: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Mathematical InductionExamples

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 9 / 23

Page 10: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Mathematical InductionExamples

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 10 / 23

Page 11: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Strong InductionIntroduction

Strong Induction

To prove that P(n) is true for all positive integers n, where P(n) is apropositional function, we complete two steps:BASIS STEP: We verify that P(1) is true.INDUCTIVE STEP: We show that the conditional statement[P(1) ∧ P(2) ∧ · · · ∧ P(k)]→ P(k + 1) is true for all positive integers k .

Strong induction is a more flexible proof technique than themathematical induction.

Strong induction is sometimes called the second principle ofmathematical induction or complete induction.

The mathematical induction and strong induction are equivalent.That is, each can be shown to be a valid proof technique assumingthat the other is valid.

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 11 / 23

Page 12: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Strong InductionExamples

Example: Show that if n is an integer greater than 1, then n can bewritten as the product of primes.

Let P(n) be the proposition that ∀n > 1, n can be written as theproduct of primes.

BASIS STEP: P(2) is true because 2 can be written as the productof a single prime number 2.

INDUCTIVE STEP: Suppose that every integer between 2 and kcan be written as the product of one or more primes.

We need to show that k + 1 can be written as a product of primes.

Case 1: k + 1 is prime. Then it is the product of one prime.

Case 2: k+1 is composite. Then k+1 can be written as ab, where aand b are integers such that 1 < a, b < k + 1. By the inductionhypothesis, a can be written as a product of primes p1p2 · · · pi and bcan be written as a product of primes q1q2 · · · qj . So then k + 1can be written as the product of primes p1p2 · · · piq1q2 · · · qj .

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 12 / 23

Page 13: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Recursive DefinitionsRecursively Defined Functions

We use two steps to define a function with the set of nonnegativeintegers as its domain:BASIS STEP: Specify the value of the function at zero.RECURSIVE STEP: Give a rule for finding its value at an integer fromits values at smaller integers.

Ex. Suppose that f is defined recursively byf (0) = 3, f (n + 1) = 2f (n) + 3. Find f (1), f (2), f (3), and f (4).

f (1) = 2f (0) + 3 = 2 · 3 + 3 = 9,

f (2) = 2f (1) + 3 = 2 · 9 + 3 = 21,

f (3) = 2f (2) + 3 = 2 · 21 + 3 = 45,

f (4) = 2f (3) + 3 = 2 · 45 + 3 = 93.

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 13 / 23

Page 14: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Recursive DefinitionsRecursively Defined Functions

EX. Give a recursive definition of an, where a is a nonzero real numberand n is a nonnegative integer.

First a0 is specified, namely, a0 = 1.

Then the rule for finding an+1 from an, namely, an+1 = a · an, forn = 0, 1, 2, 3, · · · , is given.

These equations uniquely define an for all nonnegative integers n.

EX. Give a recursive definition of∑n

k=0 ak .

The first part of the recursive definition is∑0

k=0 ak = a0.

The second part is∑n+1

k=0 ak = (∑n

k=0 ak) + an+1

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 14 / 23

Page 15: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Recursive DefinitionsRecursively Defined Functions

Recursive definitions of sets have two parts, a basis step and a recursivestep. In the basis step, an initial collection of elements is specified. Inthe recursive step, rules for forming new elements in the set from thosealready known to be in the set are provided.

EX. Consider the subset S of the set of integers recursively defined byBASIS STEP: 3 ∈ S..RECURSIVE STEP: If x ∈ S and y ∈ S, then x + y ∈ S..

The new elements found to be in S are 3 by the basis step, 3 + 3 =6 at the first application of the recursive step

3 + 6 = 6 + 3 = 9 and 6 + 6 = 12 at the second application of therecursive step, and so on.

Note that S is the set of all positive multiples of 3.

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 15 / 23

Page 16: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Recursive AlgorithmsIntroduction

An algorithm is called recursive if it solves a problem by reducing it to aninstance of the same problem with smaller input.

EX. Give a recursive algorithm for computing n!, where n is anonnegative integer.

First, we use the recursive step to write 4! = 4 · 3!. We then use therecursive step repeatedly to write 3! = 3 · 2!, 2! = 2 · 1!, and 1! = 1 · 0!.Inserting the value of 0! = 1, and working back through the steps, we seethat 1! = 1 · 1 = 1, 2! = 2 · 1! = 2, 3! = 3 · 2! = 3 · 2 = 6, and4! = 4 · 3! = 4 · 6 = 24.

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 16 / 23

Page 17: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Recursive AlgorithmsIntroduction

EX. Give a recursive algorithm for computing an, where a is a nonzeroreal number and n is a nonnegative integer.

We can base a recursive algorithm on the recursive definition of an. Thisdefinition states that an+1 = a · an for n > 0 and the initial conditiona0 = 1. To find an, successively use the recursive step to reduce theexponent until it becomes zero.

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 17 / 23

Page 18: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Recursive AlgorithmsRecursion and Iteration

A recursive definition expresses the value of a function at a positiveinteger in terms of the values of the function at smaller integers.

This means that we can devise a recursive algorithm to evaluate arecursively defined function at a positive integer.

Instead of successively reducing the computation to the evaluationof the function at smaller integers, we can start with the value ofthe function at one or more integers, the base cases, andsuccessively apply the recursive definition to find the values of thefunction at successive larger integers.

Such a procedure is called iterative.

Often an iterative approach for the evaluation of a recursivelydefined sequence requires much less computation than a procedureusing recursion

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 18 / 23

Page 19: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Recursive AlgorithmsRecursion and Iteration

The iterative and recursive procedures for finding the nth Fibonaccinumber.

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 19 / 23

Page 20: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Recursive AlgorithmsThe Merge Sort

EX. Use the merge sort to put the terms of the list 8, 2, 4, 6, 9, 7, 10, 1,5, 3 in increasing order.

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 20 / 23

Page 21: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Recursive AlgorithmsThe Merge Sort

EX. Merge the two lists 2, 3, 5, 6 and 1, 4.

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 21 / 23

Page 22: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Recursive AlgorithmsThe Merge Sort

Two sorted lists with m elements and n elements can be merged into asorted list using no more than m + n - 1 comparisons.

The number of comparisons needed to merge sort a list with n elementsis O(n log n).

ECOM 2311- Discrete Mathematics - Ch.5 Dr. Musbah Shaat 22 / 23

Page 23: Chapter # 5 : Induction and Recursionsite.iugaza.edu.ps/musbahshaat/files/chapter5_all_handout.pdf · ECOM 2311- Discrete Mathematics Chapter # 5 : Induction and Recursion Fall, 2013/2014

Homework [due 26th of Nov].From the text book, Section 5.1, page 329Questions: Q4, Q6, Q16, Q22 and Q32.From the text book, Section 5.3, page 357Questions: Q6[Parts a,c,d], Q8[Parts a,b], Q24[Parts a,b], Q26[Part a].From the text book, Section 5.4, page 370Questions: Q8, Q16, Q44, Q46[Part a] and Q49[Very important].

End of Chapter # 5