Download Discrete Mathematics Lecture 17: Induction and Recursion and more Slides Discrete Mathematics in PDF only on Docsity! CSci 2011 Discrete Mathematics Lecture 17 Docsity.com Interesting Induction Someone with zero hairs is bald. Someone with one more hair than a bald person is bald. . . turn the inductive crank…… . Therefore, someone with 1,000, 000 hairs is bald. What’s wrong with this induction? Docsity.com Second induction example Show the sum of the first n positive even integers is n2 + n Rephrased: ∀ n P(n) where P(n) = ∑ni=1 2 i = n2 + n The three parts: Base case Inductive hypothesis Inductive step Docsity.com Induction example Show that n! < nn for all n > 1 Base case: n = 2 2! < 22 2 < 4 Inductive hypothesis: assume k! < kk Inductive step: show that (k+1)! < (k+1)k+1 (k+1)! = (k+1) ⋅ k! < (k+1) kk < (k+1) (k+1)k = (k+1)k+1 Docsity.com More Examples Prove thatt if h> -1, then 1+nh ≤ (1+h)n for all non-negative integer n. Prove that n2 ≡ 1 mod 8 for all odd integer n. Docsity.com Strong induction example 1 Inductive step: Show that P(k+1) is true There are two cases: k+1 is prime It can then be written as the product of k+1 k+1 is composite It can be written as the product of two composites, a and b, where 2 ≤ a ≤ b < k+1 By the inductive hypothesis, both P(a) and P(b) are true Docsity.com Strong Induction Examples 2 Prove that every amount of 12 cents or more can be formed using just 4-cent and 5-sent stamps. Basis Step 12 = 3 * 4 cent stamp 13 = 2 * 4 + 1 * 5 14 = 1 * 4 + 2 * 5 15 = 3 * 5 Inductive step: Suppose P(j) is true for 12 ≤ j ≤ k (k≥15). It is sufficient to show that P(k+1) is true. We know that P(k-3) is true since k ≥ 15. To form postage of k+1 cents, we just need to add 1 4-cent postage to the stamps we used to form k-3 cents. Docsity.com ch 4.3, 4.4 Recursion Docsity.com Examples Can you write n! as a recursive function F(0) = 1 F(n) = n*F(n-1) Sum function: F(n) = Σni=1 n F(1) = 1 F(n+1) = (n+1) + F(n) Fibonacci Numbers F(0) = 0, F(1) = 1 F(n) = F(n-1) + F(n-2) Docsity.com F(n) grows infinitely Let α = (1+√5)/2 = 1.61803… For n ≥3, F(n) > αn-2 Proof by induction. Hint for the inductive step: Solve x2-x-1=0 for x Docsity.com Strings can be defined recursively Σ: Alphabet (set of symbols) λ: Empty String Σ*: set of all strings over the alphabet Basis: λ∈Σ Recursive Step: If w∈Σ* and x∈Σ, then wx ∈ Σ* wx: string w followed by symbol x Docsity.com Extended Binary Trees Basis: The empty set is an extended binary tree Recursive step: if T1 and T2 are extended binary trees, then the tree T1T2 obtained by connecting a root r to the roots of T1 and T2 is also an extended binary tree r Docsity.com Complete Binary Trees Basis: a single vertex is a complete binary tree Recursive step: if T1 and T2 are complete binary trees, then the tree T1T2 obtained by connecting a root r to the roots of T1 and T2 is also a complete binary tree r Docsity.com Recursive Algorithms An algorithm is called recursive if it solves a problem by reducing it to a smaller instance of the same problem. Computing n! Procedure factorial(n) If n=0, return 1 Else return n*factorial(n-1) Computing GCD gcd(a,b) /* assumption a < b */ If a=0, then return b Else return gcd(b mod a, a) Docsity.com