CSC236H Lecture 2 Ilir Dema September 19, 2018
Simple Induction Useful to prove statements depending on natural numbers Define a predicate P(n) Prove the base case P(b) Prove that for all n b, P(n) P(n + 1).
Is it enough? Prove by induction that one needs precisely n 1 cuts to cut a chocolate bar in n pieces.
ConcepTest Prove by induction that one needs precisely n 1 cuts to cut a chocolate bar in n pieces. In a proof by simple induction: A. The base case cannot be proved B. The inductive hypothesis (I.H.) can t be stated C. It is difficult to use the I.H. to prove the inductive case D. The proof is not possible
Prime or Product of Primes We want to prove that every natural number greater than 1 can be written as a product of primes. Some examples: 2 = 2 (2 itself is prime) 4 = 2 2 28 = 2 2 7 100 = 5 5 2 2 101 = 101 (101 itself is prime) 57 =? (Grothendieck prime)
Prime or Product of Primes We want to prove that every natural number greater than 1 can be written as a product of primes. Try simple induction: Some examples: 2 = 2 (base case) Let s try to get some intuition for the inductive step... Say we check 8 = 2 2. How does that help prove 9 = 3 3?
Prime or Product of Primes
Aye, captain. Complete Induction Principle of complete (strong) induction: (1) If P(b) is True, (2) And P(b) P(b + 1)... P(n) P(n + 1) is True for all n b, Then P(n) is True for all integers n b.
Intuition for Complete Induction Suppose that we prove P(0) We can therefore use P(0) to prove P(1) Then we can use both P(0) and P(1) to prove P(2) Then we can use all three of P(0), P(1), and P(2) to prove P(3)...
ConcepTest Read Presentation 1 on the handout. Which of the following is true? A. The proof is invalid; the inductive hypothesis cannot be assumed B. The proof is invalid; the base case for 18 is incorrect C. The proof is invalid; we must argue that 17 cents cannot be formed from 4-cent and 7-cent stamps D. The proof is valid E. The claim is false; a counterexample can be found
Look, ma, I won 6 poins!
ConcepTest You begin with a stack of n cups. On each move, you break a stack of cups into two stacks of cups. If you break a stack of a + b cups into a stack of a cups and a stack of b cups, you get ab points. The game ends when there is one cup per stack. What is the maximum number of points that you can get starting with 5 cups? A. 5 B. 10 C. 15 D. 120
Unstacking cups... P(n): no matter how we unstack n cups, we get a score of n(n 1)/2 points We can prove this using complete induction. (1) For n = 1, we can t do any unstacking, so we get 0 points. 1(1 1)/2 = 0, so the formula is correct for the base case.
ConcepTest P(n): no matter how we unstack n cups, we get a score of n(n 1)/2 points In the inductive step, we have n + 1 cups. Let 1 k n. How many total points do we get for unstacking n + 1 cups into a stack of k and a stack of n + 1 k? A. k(n + 1 k) B. k(n + 1 k) + k(k 1)/2 C. k(n + 1 k) + k(k 1)/2 + (n + 1 k)(n k)/2 D. k(n + 1 k) + k(k 1)/2 (n + 1 k)(n k)/2
Application: Continued Fractions
What is a continued fraction? Formally, a continued fraction is: An integer n A fraction n + 1 F where n is an integer and F is a continued fraction
All rational numbers can be represented as continued fractions
Proof P(d): A rational with denominator d > 0 can be written as continued fraction. (Any rational r = n/d can be written with d > 0 so the above suffices) Base case: d = 1. Then r = n/1 = n is a continued fraction. Inductive step: Assume for some d N with d > 1, for all 1 d < d, P(d ) is true. Let r = n/d a rational with denominator d. Then n = qd + r. Case 1: r = 0. Then r = qd/d = q, so the representation of r is the continued fraction q. Case 2: 0 < r < d. Then r = n d = q + r d = q + 1 d r. Apply inductive hypothesis and conclude.
Summary: Simple/Complete Induction Now we have seen both simple/weak and complete/strong induction. If using one number back is sufficient to prove the claim for the next number, then use simple induction If jumping further back is necessary, use complete induction In terms of what they can prove: the two techniques are equivalent! And in terms of proof structure: they are very similar!
Summary: Simple/Complete Induction... For both simple and complete induction: Prove the base case(s) of P Use induction hypothesis to prove P(n + 1) Use principle of induction to conclude that P holds for the base case and all larger numbers The difference between simple and complete induction is in the induction hypothesis Simple induction: assume P(n) Complete induction: assume P(b), P(b + 1),..., P(n)
Where do natural numbers come from? Consider the following recursively-defined set S, the smallest set such that: S. If p S then {p} p S. What is the relation of S and N?
ConcepTest Consider the following recursively-defined set S, the smallest set such that: ɛ (the empty string ) and 1 are in S. If w is a string in S, then so is w00. If w is a string in S, then so is w01. Which of the following is true? A. Every string in S has no consecutive 1s B. Every binary string with no consecutive 1s is in S C. Both of the above are true D. None of the above is true
Structural Induction A recursively-defined set has One or more base case elements One or more rules for generating new, larger elements of the set from existing elements in the set Structural induction is a technique for proving that every element in such a set has a given property For the converse (every element that has a given property is in the set), use simple or complete induction!
Structural Induction... Principle of structural induction: Suppose that X is a recursively-defined set and P is some predicate. (1) If P is true for each base element of X, (2) and, under the assumption that P(e) is true for element e of X, we find that each recursive rule produces an element that satisfies P, Then P is true for all elements of X We must use (ii) separately on each recursive rule!
Structural Induction Proof Consider the following recursively-defined set S, the smallest set such that: ɛ (the empty string ) and 1 are in S. If w is a string in S, then so is w00. If w is a string in S, then so is w01. Prove, for all s S, that s does not contain two consecutive 1s.
Exercise 1 Exercise 1 on handout.
Structural induction
ConcepTest Here is a recursive definition for some set T of non-empty binary trees. A single node is in T If t 1 and t 2 are in T, then the bigger tree with root r connected to the roots of t 1 and t 2 is in T If t 1 is in T, then the bigger tree with root r connected to the root of t 1 to the left or right is in T Nothing else is in T Which of the following is true? A. Every element of T has m nodes with two children and m + 1 leaves B. Every binary tree that has m nodes with two children and m + 1 leaves is in T C. Both of the above are true D. None of the above is true
Heap Example Suppose we store numbers in the nodes of a full binary tree. The numbers obey the heap property if, for every node X in the tree, the value in X is at least as big as the value in each of Xs children.
Heap Example Prove that If a full binary tree has the heap property, then the value in the root of the tree is at least as large as the value in any node of the tree. Base Case: If a tree contains only one node, obviously the largest value in the tree lives in the root! Inductive Case: Suppose that the claim is true for trees X and Y. We need to show that the claim is also true for the tree T that consists of a root node plus subtrees X and Y.
Heap Example (continued) Let r be the root of the whole tree T. Suppose p and q are the children of r, i.e. the root nodes of X and Y. Since T has the heap property, v(r) v(p) and v(r) v(q). Suppose that x is any node of T. We need to show that v(r) v(x). There are three cases: Case 1: x = r. This is obvious. Case 2: x is any node in the subtree X. By the inductive hypothesis v(p) v(x). But we know that v(r) v(p). So v(p) v(x). Case 3: x is any node in the subtree Y. Similar to case 2.