CS 103 Discrete Structures Lecture 13 Induction and Recursion (1)

Slides:



Advertisements
Similar presentations
22C:19 Discrete Structures Induction and Recursion Fall 2014 Sukumar Ghosh.
Advertisements

Recursive Definitions and Structural Induction
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
Induction and Recursion. Odd Powers Are Odd Fact: If m is odd and n is odd, then nm is odd. Proposition: for an odd number m, m k is odd for all non-negative.
UCI ICS/Math 6A, Summer Recursion -1 after Strong Induction “Normal” Induction “Normal” Induction: If we prove.
Induction and recursion
UCI ICS/Math 6D5-Recursion -1 Strong Induction “Normal” Induction “Normal” Induction: If we prove that 1) P(n 0 ) 2) For any k≥n 0, if P(k) then P(k+1)
CSE115/ENGR160 Discrete Mathematics 04/03/12 Ming-Hsuan Yang UC Merced 1.
CSE115/ENGR160 Discrete Mathematics 03/22/12 Ming-Hsuan Yang UC Merced 1.
CSE115/ENGR160 Discrete Mathematics 03/31/11
Chapter Mathematical Induction
1 Section 3.4 Recursive Definitions. 2 Recursion Recursion is the process of defining an object in terms of itself Technique can be used to define sequences,
1 Section 3.3 Mathematical Induction. 2 Technique used extensively to prove results about large variety of discrete objects Can only be used to prove.
CSE115/ENGR160 Discrete Mathematics 03/29/11 Ming-Hsuan Yang UC Merced 1.
Climbing an Infinite Ladder
Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.
Induction and recursion
Induction and recursion
Recursive Definitions and Structural Induction
Discrete Mathematics CS 2610 March 26, 2009 Skip: structural induction generalized induction Skip section 4.5.
Induction and recursion
Chapter 6 Mathematical Induction
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Chapter 4 Induction and Recursion 歐亞書局.
1 Introduction to Abstract Mathematics Chapter 4: Sequences and Mathematical Induction Instructor: Hayk Melikya 4.1- Sequences. 4.2,
Chapter 4: Induction and Recursion
Section 5.3. Section Summary Recursively Defined Functions Recursively Defined Sets and Structures Structural Induction.
Induction and recursion
Chapter 5 With Question/Answer Animations. Section 5.1.
4.3 Recursive Definitions and Structural Induction Sometimes it is difficult to define an object explicitly. However, it may be easy to define this object.
Induction Proof. Well-ordering A set S is well ordered if every subset has a least element. [0, 1] is not well ordered since (0,1] has no least element.
Section 3.3: Mathematical Induction Mathematical induction is a proof technique that can be used to prove theorems of the form:  n  Z +,P(n) We have.
ICS 253: Discrete Structures I Induction and Recursion King Fahd University of Petroleum & Minerals Information & Computer Science Department.
CompSci 102 Discrete Math for Computer Science March 1, 2012 Prof. Rodger Slides modified from Rosen.
Foundations of Discrete Mathematics Chapters 5 By Dr. Dalia M. Gil, Ph.D.
1 INFO 2950 Prof. Carla Gomes Module Induction Rosen, Chapter 4.
1 Recursive Definitions and Structural Induction CS 202 Epp section ??? Aaron Bloomfield.
Mathematical Induction Section 5.1. Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If.
Mathematical Induction
CompSci 102 Discrete Math for Computer Science March 13, 2012 Prof. Rodger Slides modified from Rosen.
Chapter 5. Section 5.1 Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If we can reach.
Chapter 5 Kenneth Rosen, Discrete Mathematics and its Applications, 7th edition, McGraw Hill Instructor: Longin Jan Latecki, Copyright.
Section 5.1. Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If we can reach a particular.
Chapter 5 With Question/Answer Animations 1. Chapter Summary Mathematical Induction - Sec 5.1 Strong Induction and Well-Ordering - Sec 5.2 Lecture 18.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Section Recursion  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Mathematical Induction What it is? Why is it a legitimate proof method? How to use it?
Mathematical Induction And Recursion Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS ) 1.
3.3 Mathematical Induction 1 Follow me for a walk through...
Chapter 5 1. Chapter Summary  Mathematical Induction  Strong Induction  Recursive Definitions  Structural Induction  Recursive Algorithms.
Chapter 4: Induction and Recursion
Induction and recursion
Induction and Recursion Chapter 5
CSE15 Discrete Mathematics 03/22/17
Advanced Algorithms Analysis and Design
CS2210:0001Discrete Structures Induction and Recursion
Induction and recursion
Induction and Recursion
Mathematical Induction Recursion
Discrete Structures for Computer Science
Chapter 5 Induction and Recursion
Induction and recursion
Applied Discrete Mathematics Week 9: Integer Properties
Induction Chapter
Advanced Analysis of Algorithms
Mathematical Induction
Mathematical Induction
Induction and recursion
Induction and recursion
Agenda Proofs (Konsep Pembuktian) Direct Proofs & Counterexamples
Chapter 4 (Part 2): Mathematical Reasoning, Induction & Recursion
Presentation transcript:

CS 103 Discrete Structures Lecture 13 Induction and Recursion (1) Chapter 1 section 1.1 by Dr. Mosaad Hassan

Induction and recursion Chapter 5 With Question/Answer Animations

Chapter Summary Mathematical Induction Strong Induction Well-Ordering Recursive Definitions Structural Induction

Mathematical Induction Section 5.1

Section Summary Mathematical Induction Examples of Proof by Mathematical Induction Guidelines for Proofs by Mathematical Induction

Mathematical Induction A technique for constructing proofs Mathematical induction is based on the following rule of inference: (P(1)  k [P(k)  P(k + 1)])  n P(n), where nZ+ Proofs using induction require two steps: Basis step: Show that the statement P(n) holds for n = 1 Inductive step: Show that if the statement P(n) holds for a positive integer n = k then it also holds for n = k + 1. P(k) is called the inductive hypothesis.

Mathematical Induction: Example Consider an infinite ladder, as shown in the figure To know whether we can reach every step on this ladder, we know two things: We can reach the first rung of the ladder If we can reach a particular rung of the ladder, then we can reach the next one By (1) and (2), we conclude that we can reach every rung

Proof by Induction Mathematical induction can be used to prove that P(n) is true for all positive integers n The proof by induction has two steps: Basis step: Verify that P(1) is true Inductive step: Show that for all +ive integers k, if P(k) is true, then P(k + 1) is true. That is, show that P(k) → P(k + 1) is true for all +ive integers k To complete inductive step, Assume P(k) is true for an arbitrary +ive integer k Show that if P(k) is true then P(k + 1) must also be true If we verify those two steps, then P(n) is true for every +ive integer n The above can be stated as a rule of inference as: (P(1)  k [P(k)  P(k + 1)])  n P(n), where n  Z+

Proof by Induction: Example 1 1 + 2 + 3 +…+ n = n(n + 1)/2, where n  Z+ Let P(n) be 1 + 2 + 3 +…+ n = n(n + 1)/2 Basis step: P(1) is true since 1 = 1(1 + 1)/2 Inductive step: Let P(k) be true  1 + 2 + 3 + … + k = k(k + 1)/2 Based on that, we will show P(k + 1) to be true For that, add (k + 1) to both sides of P(k) 1 + 2 + 3 +…+ k + (k + 1) = k(k + 1)/2 + (k + 1) = [k(k + 1) + 2(k + 1)]/2 = (k + 1)(k + 2)/2  P(k + 1) is true when P(k) is true (P(1)  k [P(k)  P(k + 1)])  n P(n), where n  Z+ Theorem is proved

Proof by Induction: Example 2 Conjecture (guess) a formula for the sum of the first n positive odd integers and then prove your conjecture using mathematical induction. The sum of the first n positive odd integers for n = 1, 2, 3, 4, 5 are: 1 = 1 1 + 3 = 4 1 + 3 + 5 = 9 1 + 3 + 5 + 7 = 16 1 + 3 + 5 + 7 + 9 = 25 The formula seems to be 1 + 3 + 5 + … + (2n-1) = n2

Proof by Induction: Example 2 Let P(n) be 1 + 3 + 5 + … + (2n - 1) = n2 Basis step: P(1) is true since 1 = 12 Inductive step: Let P(k) be true 1 + 3 + 5 + … + (2k - 1) = k2 is true Based on that, now we show P(k + 1) to be true. For that, we add the (k+1)st term 2(k + 1)-1 to both sides 1 + 3 + 5 +…+ (2k - 1) + 2(k + 1) - 1 = k2 + 2(k + 1) - 1 = k2 + 2k + 1 = (k + 1)2  P(k+1) is true when P(k) is true (P(1)  k [P(k)  P(k + 1)])  n P(n), where n  Z+ Theorem is proved

Proof by Induction: Example 3 1 + 2 + 22 +...+ 2n = 2n+1 – 1, where n Z and n  0 Let P(n) be 1 + 2 + 22 +... + 2n = 2n+1 - 1 Basis step: P(0) is true since 1 = 20 = 21 - 1 Inductive step: Let P(k) be true 1 + 2 + 22 + … + 2k = 2k+1 - 1 is true Based on that, now we show P(k + 1) to be true 1 + 2 + 22 + … + 2k + 2k+1 = 2k+1 - 1 + 2k+1 = 2(2k+1) - 1 = 2k+2 - 1  P(k + 1) is true when P(k) is true (P(1)  k [P(k)  P(k + 1)])  n P(n), n  Z+, n  0 Theorem is proved Note: Instead of starting with 1, we are starting with 0. As a rule, we start with the lowest allowed value, which generally is 1

Proof by Induction: Example 4 Sums of Geometric Progressions: Use mathematical induction to prove this formula for the sum of a finite number of terms of a geometric progression: where n is a non-negative integer Basis step: P(0) is true because

Proof by Induction: Example 4 Inductive step: Let P(k) be true Based on that, we show P(k + 1) to be true. For that, add the (k + 1)st term to both sides of P(k)  P(k + 1) is true when P(k) is true (P(1)  k [P(k)  P(k + 1)])  n P(n), where n  Z+

Proving Inequalities: Example 1 n < 2n, where n  Z+ Let P(n) be n < 2n Basis step: P(1) is true, because 1 < 21 = 2 Inductive step: Let P(k) be true k < 2k is true Based on that, now we show P(k + 1) to be true k + 1 < 2k + 1 (add 1 to both sides of P(k)) ∵2k + 1 < 2k + 2k (1 < 2k for all k) k + 1 < 2k + 2k k + 1 < 2(2k) k + 1 < 2k+1  P(k + 1) is true when P(k) is true (P(1)  k [P(k)  P(k + 1)])  n P(n), n  Z+

Proving Inequalities: Example 2 2n < n! where n  Z+ and n  4 Let P(n) be 2n < n! Basis step: P(4) is true, because 24 = 16 < 4! = 24 Inductive step: Let P(k) be true 2k < k! is true Based on that, now we show P(k + 1) to be true 2(2k) < 2(k!) (multiply both sides of P(k) by 2) 2k+1 < (k + 1)k! (2 < k + 1 for all k) 2k+1 < (k + 1)!  P(k + 1) is true when P(k) is true (P(1)  k [P(k)  P(k + 1)])  n P(n), n  Z+, n  4

Proving Divisibility: Example Prove that n3 - n is divisible by 3 where n  Z+ Let P(n) be the proposition that n3 - n is divisible by 3 Basis step: P(1) is true since 13 - 1 = 0, which is divisible by 3 Inductive step: Assume P(k) holds, i.e., k3 - k is divisible by 3, for an arbitrary positive integer k. To show that P(k + 1) follows, (k + 1)3 - (k + 1) = (k3 + 3k2 + 3k + 1) - (k + 1) = (k3 - k) + 3(k2 + k) By the inductive hypothesis, the first term (k3 - k) is divisible by 3 and the 2nd term is divisible by 3 since it is an integer multiplied by 3. Therefore, the sum of the two term is divisible by 3 P(k + 1) is true when P(k) is true (P(1)  k [P(k)  P(k + 1)])  n P(n), where n  Z+

Mathematical Induction: Template

Section 5.1: Exercises For both exercises, answer the following questions:

Exercises

Exercises

Exercises

CS 103 Discrete Structures Lecture 14 Induction and Recursion (2) Chapter 1 section 1.1 by Dr. Mosaad Hassan

Strong Induction and Well-Ordering Section 5.2

Section Summary Strong Induction Example Proofs using Strong Induction Well-Ordering Property

Weak and Strong Induction Weak (or Mathematical) Induction Inductive Step: Assume P(k) to be true, and use that (and only that) to show P(k + 1) is true P(k)  P(k + 1) Strong Induction Inductive Step: Assume P(1), P(2),…, P(k) to be true, and use that to show that P(k + 1) is true [P(1)  P(2)  P(3)  …  P(k)]  P(k + 1)

Strong Induction To prove that P(n) is true for all positive integers n, where P(n) is a propositional function, complete two steps: Basis Step: Verify that the proposition P(1) is true Inductive Step: Show the conditional statement [P(1) ∧ P(2) ∧∙∙∙ ∧ P(k)] → P(k + 1) holds for all positive integers k Strong Induction is sometimes called the second principle of mathematical induction or complete induction

Strong Induction: Infinite Ladder Strong induction tells us that we can reach all rungs if: We can reach the first rung of the ladder For every integer k, if we can reach the first k rungs, then we can reach the (k + 1)st rung By doing so we will have then shown by strong induction that for every positive integer n, P(n) holds, i.e., we can reach the nth rung of the ladder

Strong Induction: Example 1 For an infinite ladder, prove that we can reach every rung if: we can reach the 1st and 2nd rungs and if we can reach a rung, then we can reach 2 rungs higher (Try this with mathematical induction!) Solution: Proof uses strong induction BASIS STEP: We can reach the 1st rung INDUCTIVE STEP: The inductive hypothesis is that we can reach the first k rungs, for any k ≥ 2. We can reach the (k + 1)st rung since we can reach the (k − 1)st rung by the inductive hypothesis  we can reach all rungs of the ladder

Which Form of Induction Should Be Used? We can always use strong induction instead of mathematical induction. But there is no reason to use it if it is simpler to use mathematical induction In fact, the principles of mathematical induction and strong induction are equivalent

Strong Induction: Example 2 If n  Z and n > 1, then n can be written as the product of primes Proof: Let P(n) be the proposition that n can be written as a product of primes BASIS STEP: P(2) is true since 2 can be written as a product one prime, itself INDUCTIVE STEP: The inductive hypothesis is that P(j) is true for all integers j with 2 ≤ j ≤ k. To show that P(k + 1) must be true under this assumption, two cases need to be considered: If k + 1 is prime, then P(k + 1) is true Otherwise, k + 1 is composite and can be written as the product of two positive integers a and b with 2 ≤ a ≤ b < (k + 1). By the inductive hypothesis a and b can be written as the product of primes and therefore k + 1 can also be written as the product of those primes Integers greater than 1 can be written as the product of primes

Strong Induction: Example 3 Prove that every amount of postage of 12 cents or more can be formed using just 4-cent and 5-cent stamps Proof: Let P(n) be the proposition that postage of n cents can be formed using 4-cent and 5-cent stamps BASIS STEP: P(12), P(13), P(14), and P(15) hold P(12) uses three 4-cent stamps P(13) uses two 4-cent stamps and one 5-cent stamp P(14) uses one 4-cent stamp and two 5-cent stamps P(15) uses three 5-cent stamps INDUCTIVE STEP: The inductive hypothesis states that P(j) holds for 12 ≤ j ≤ k, where k ≥ 15. Assuming the inductive hypothesis, it can be shown that P(k + 1) holds Using the inductive hypothesis, P(k − 3) holds since k − 3 ≥ 12. To form postage of k + 1 cents, add a 4-cent stamp to the postage for k − 3 cents P(n) holds for all n ≥ 12

Same Example, but with Mathematical Induction Prove that every amount of postage of 12 cents or more can be formed using just 4-cent and 5-cent stamps Proof: Let P(n) be the proposition that postage of n cents can be formed using 4-cent and 5-cent stamps BASIS STEP: Postage of 12 cents can be formed using three 4-cent stamps, therefore P(12) is true INDUCTIVE STEP: The inductive hypothesis P(k) for any positive integer k is that postage of k cents can be formed using 4-cent and 5-cent stamps. To show P(k + 1) where k ≥ 12, consider two cases: If at least one 4-cent stamp has been used, then a 4-cent stamp can be replaced with a 5-cent stamp to yield a total of k + 1 cents Otherwise, no 4-cent stamp have been used and at least three 5-cent stamps were used. Three 5-cent stamps can be replaced by four 4-cent stamps to yield a total of k + 1 cents P(n) holds for all n ≥ 12

Well-Ordering Property Every nonempty set of nonnegative integers has a least element Example 1: The set {2, 3, 9} has a least element, i.e. 1 Example 2: The set of prime numbers has a least element, i.e. 2 This property is one of the axioms of the positive integers and is equivalent to mathematical induction and strong induction It can be generalized to all sets instead of just integers Definition: A set is well ordered if every subset has a least element Example 1: N is well ordered under ≤ Example 2: The set of finite strings over an alphabet using lexicographic ordering is well ordered

Using the Well-Ordering Property in Proofs The Division Algorithm: If n  Z and d  Z+, then there are unique integers q & r, 0 ≤ r < d, such that n = dq + r. n:dividend, d:divisor, q:quotient, r:remainder, e.g. 43 = 8·5+3 Proof: Let S  Z+ of the form n - dq. S is nonempty since -dq can be made as large as needed By the well-ordering property, S has a least element r = n - dq0. Integer r  N. It also must be the case that r < d. If it were not, then there would be a smaller nonnegative element in S, namely, n - d(q0 + 1). To see this, suppose that r  d. Because n = d(q0 + 1), it follows that n - dq0 - d = r - d  0 Consequently, there are integers q and r with 0 ≤ r < d

Section 5.2: Exercises Let a1 = 2, a2 = 9, and an = 2an−1 + 3an−2 for n  3. Use strong induction to show that an < 3n for all positive integers n

Recursive Definitions and Structural Induction Section 5.3

Section Summary Recursively Defined Functions Recursively Defined Sets and Structures Structural Induction Generalized Induction

Recursively Defined Functions A recursive or inductive definition of a function consists of two steps BASIS 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

Recursive Functions: Examples Example 1: Suppose f is defined by: f(0) = 3, f(n + 1) = 2f(n) + 3 Find f(1), f(2), f(3), f(4) Solution: 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 Example 2: Give a recursive definition of the factorial function n! f(0) = 1 f(n + 1) = (n + 1)∙ f(n)

Recursive Functions: Example 3 Give a recursive definition of: Solution: The first part of the definition is The second part is

Recursive Functions: Example 4 The Fibonacci numbers are defined as follows: f0 = 0 f1 = 1 fn = fn−1 + fn−2 Find f2, f3 , f4 , f5 f2 = f1 + f0 = 1 + 0 = 1 f3 = f2 + f1 = 1 + 1 = 2 f4 = f3 + f2 = 2 + 1 = 3 f5 = f4 + f3 = 3 + 2 = 5 In Chapter 8, we will use the Fibonacci numbers to model population growth of rabbits. This was an application described by Fibonacci himself

CS 103 Discrete Structures Lecture 15 Induction and Recursion (3) Chapter 1 section 1.1 by Dr. Mosaad Hassan

Recursively Defined Sets Recursive definitions of sets have two parts: The basis step specifies an initial collection of elements The recursive step gives the rules for forming new elements in the set from those already known to be in the set Sometimes the recursive definition has an exclusion rule, which specifies that the set contains nothing other than those elements specified in the basis step and generated by applications of the rules in the recursive step We will always assume that the exclusion rule holds, even if it is not explicitly mentioned We will later develop a form of induction, called structural induction, to prove results about recursively defined sets

Recursively Defined Sets: Examples Example 1: Subset of integers S BASIS STEP: 3 ∊ S RECURSIVE STEP: If x ∊ S and y ∊ S, then x + y is in S Initially 3 is in S, then 3 + 3 = 6, then 3 + 6 = 9, etc. Example 2: The natural numbers N BASIS STEP: 0 ∊ N RECURSIVE STEP: If n is in N, then n + 1 is in N Initially 0 is in S, then 0 + 1 = 1, then 1 + 1 = 2, etc.

Recursively Defined Strings The set Σ* of strings over the alphabet Σ: BASIS STEP: λ ∊ Σ* (λ is the empty string) RECURSIVE STEP: If w is in Σ* and x is in Σ, then wxΣ* Example 1: If Σ = {0, 1}, the strings in Σ* are the set of all bit strings, λ, 0, 1, 00, 01, 10, 11, 000, 001, etc. Example 2: If Σ = {a, b}, show that aab is in Σ* Since λ ∊ Σ* and a ∊ Σ, therefore a ∊ Σ* Since a ∊ Σ* and a ∊ Σ, therefore aa ∊ Σ* Since aa ∊ Σ* and b ∊ Σ, therefore aab ∊ Σ*

String Concatenation Strings can be combined via the operation of concatenation Let Σ be the set of alphabet and Σ* be the set of strings formed from the alphabet in Σ. We can define the concatenation of two strings, denoted by “∙”, recursively as: BASIS STEP: If w  Σ*, then w ∙ λ = w RECURSIVE STEP: If w1  Σ* and w2  Σ* and x  Σ, then w1 ∙ (w2 x) = (w1 ∙ w2)x Often w1 ∙ w2 is written as w1w2 If w1 = abra and w2 = cadabra, then w1w2 = abracadabra

Recursive Definitions: String Length The length of a string can be recursively defined by: BASIS STEP: l(w) = 0 RECURSIVE STEP: l(wx) = l(w) + 1 if w ∊ Σ* and x ∊ Σ

Example: Balanced Parentheses Give a recursive definition of the set of balanced parentheses P Solution: BASIS STEP: () ∊ P RECURSIVE STEP: If w ∊ P, then ()w ∊ P, (w) ∊ P and w() ∊ P Show that (() ()) is in P () ∊ P and w() ∊ P imply that ()() ∊ P Furthermore, (w) ∊ P implies that (()()) ∊ P Why is ))(() not in P? Because P includes only matched pairs of parentheses

Well-Formed Formulae The set of well-formed formulae in propositional logic involving T, F, propositional variables, and operators from the set {¬, ∧, ∨, →, ↔} BASIS STEP: T, F, and x, where x is a propositional variable, are well-formed formulae RECURSIVE STEP: If E and F are well formed formulae, then (¬E), (E ∧ F), (E ∨ F), (E → F), (E ↔ F), are well-formed formulae Example 1: [(p ∨q) → (q ∧ F)] is a well-formed formula Example 2: pq ∧ is not a well formed formula

Rooted Trees The set of rooted trees, where a rooted tree consists of a set of vertices containing a distinguished vertex called the root, and edges connecting these vertices, can be defined recursively by these steps: BASIS STEP: A single vertex r is a rooted tree RECURSIVE STEP: Suppose that T1, T2, …,Tn are disjoint rooted trees with roots r1, r2,…,rn, respectively. Then the graph formed by starting with a root r, which is not in any of the rooted trees T1, T2, …,Tn , and adding an edge from r to each of the vertices r1, r2,…,rn, is also a rooted tree

Building Up Rooted Trees Trees are studied extensively in Chapter 11 Next we look at a special type of tree, the full binary tree

Full Binary Trees A full binary tree is a tree in which every node has either zero or two children The set of full binary trees can be defined recursively by these steps BASIS STEP: There is a full binary tree consisting of only a single vertex r RECURSIVE STEP: If T1 and T2 are disjoint full binary trees, there is a full binary tree, denoted by T1∙T2, consisting of a root r together with edges connecting the root to each of the roots of the left subtree T1 and the right subtree T2

Building Up Full Binary Trees

Induction & Recursively Defined Sets: Example Prove that A = S if set S is defined by a recursive definition: Basis step: 3 ∊ S Recursive step: if x ∊ S and y ∊ S, then (x + y) ∊ S and A = { 3, 6, 9, 12, 15, … } = { x | x = 3n and n  Z+ } Proof: To prove that A = S, show that A  S and S  A A  S: Let P(n) be 3n ∊ S, i.e. every element of A is in S BASIS STEP: 3∙1 = 3 ∊ S, by the 1st part of recursive definition INDUCTIVE STEP: Assume P(k) is true, i.e. 3k ∊ S. Since 3 ∊ S, it follows that 3k + 3 = 3(k + 1) ∊ S.  P(k + 1) is true S  A: BASIS STEP: 3 ∊ S by the 1st part of recursive definition, and 3 = 3∙1 INDUCTIVE STEP: The 2nd part of the recursive definition adds x + y to S, if both x and y are in S. If x and y are both in A, then both x and y are divisible by 3.  their sum x + y is also divisible by 3 We used mathematical induction to prove a result about a recursively defined set. Next we study a more direct form of induction for proving results about recursively defined sets

Structural Induction To prove a property of the elements of a recursively defined set, we use structural induction BASIS STEP: Show that the result holds for all elements specified in the basis step of the recursive definition RECURSIVE STEP: Show that if the statement is true for each of the elements used to construct new elements in the recursive step of the definition, the result holds for these new elements The validity of structural induction can be shown to follow from the principle of mathematical induction

Full Binary Trees: Height, Vertices Height h(T) of a full binary tree T is defined recursively as: BASIS STEP: The height of a full binary tree T consisting of only a root r is h(T) = 0 RECURSIVE STEP: If T1 and T2 are full binary trees, then the full binary tree T = T1∙T2 has height h(T) = 1 + max[h(T1), h(T2)] Number of vertices n(T) of a full binary tree T satisfies the following recursive formula: BASIS STEP: The number of vertices of a full binary tree T consisting of only a root r is n(T) = 1 RECURSIVE STEP: If T1 and T2 are full binary trees, then the full binary tree T = T1∙T2 has the number of vertices n(T) = 1 + n(T1) + n(T2)

Structural Induction & Binary Trees If T is a full binary tree, then n(T) ≤ 2h(T)+1 – 1 Proof: Use structural induction BASIS STEP: The result holds for a full binary tree consisting only of a root, n(T) = 1 and h(T) = 0. Hence, n(T) = 1 ≤ 20+1 – 1 = 1 RECURSIVE STEP: Assume n(T1) ≤ 2h(T1)+1 – 1 and also n(T2) ≤ 2h(T2)+1 – 1 whenever T1 and T2 are full binary trees n(T) = 1 + n(T1) + n(T2) by recursive formula of n(T) ≤ 1 + (2h(T1)+1 –1) + (2h(T2)+1 –1) by inductive hypothesis ≤ 2∙max[2h(T1)+1 , 2h(T2)+1 ] – 1 because the sum of two terms is at most two times the larger = 2∙2max(h(T1), h(T2))+1 – 1 max(2x , 2y)= 2max(x,y) = 2∙2h(t) – 1 by recursive definition of h(T) = 2h(t)+1 – 1 −2 .

Generalized Induction Generalized induction is used to prove results about sets (other than the integers) that have the well-ordering property Example: Consider an ordering on N⨉N, ordered pairs of nonnegative integers. Specify that (x1, y1) is less than or equal to (x2, y2) if either x1 < x2, or x1 = x2 and y1 < y2 . This is called the lexicographic ordering Strings are also commonly ordered by a lexicographic ordering The next example uses generalized induction to prove a result about ordered pairs from N⨉N

Generalized Induction: Example If am,n is defined for (m, n) ∊ N×N by a0,0 = 0 and Show that am,n = m + n(n + 1)/2 is defined for all (m,n)∊N×N Solution: Use generalized induction BASIS STEP: a0,0 = 0 = 0 + 0(0 + 1)/2 INDUCTIVE STEP: Assume that am̍,n̍ = m̍+ n̍(n̍ + 1)/2 whenever (m̍,n̍) is less than (m,n) in the lexicographic ordering of N×N If n = 0, by the inductive hypothesis we can conclude am,n = am−1,n + 1 = m − 1 + n(n + 1)/2 + 1 = m + n(n + 1)/2 If n > 0, by the inductive hypothesis we can conclude am,n = am−1,n + 1 = m + n(n − 1)/2 + n = m + n(n + 1)/2

Section 5.3: Exercises Find f(2) and f(3) if f(n) = 2f(n − 1) + 6 and f(0) = 3 Find f(2) and f(3) if f(n) = f(n − 1) · f(n − 2) + 1 and f(0) = 1, f(1) = 4 Give a recursive definition with initial condition(s) for the function f(n) = 2n, n = 1, 2, 3, . . . Give a recursive definition with initial condition(s) for the function f(n) = n!, n = 0, 1, 2, . . . Give a recursive definition with initial condition(s) of the set S = {3, 7, 11, 15, 19, 23, . . .} Give a recursive definition with initial condition(s) of the set S = {x | x is a multiple of 5, x  Z+} Give a recursive definition with initial condition(s) of the strings 1, 111, 11111, 1111111, . . .