Worked Proofs and Proof Critiques for Induction
CPSC 121
Worked Proof: Introductions for a Group of Size n
Insight: Take one person out of a group of n, and you have a group of n-1.
Definitions: An “introduction” is one person saying hello to one other person.
Theorem: For a group of n people to introduce themselves requires n(n-1) introductions.
Proof:
Basecase:A group of 1 person requires no introductions. So, when n = 1: 0 = 1*0 = 1(1-1).
Inductive hypothesis: Assume,for an arbitrary integer k > 1, that a group of k-1 people requires
(k-1)((k-1)-1)=(k-1)(k-2) introductions.
Inductive step:Under this assumption, we show that a group of k people takes k(k-1) introductions.
Consider a group of k people. Remove one person from the group. What remains is a group of k-1 people, who can introduce themselves by the inductive hypothesis using (k-1)(k-2) introductions. To finish with the group of k, the remaining person must greet and be greeted by each of the (k-1) other people, for 2(k-1) additional introductions.
So, k people take:
(k-1)(k-2) + 2(k-1)= (k-1)[(k-2) + 2]
= (k-1)k
= k(k-1).
This concludes our inductive proof. Therefore a group of size n takes n(n-1) introductions.
QED
IMPORTANT POINT: The math above is useless if you don’t establish how the math connects to the original problem. This induction is not about proving that (k-1)((k-1)-1) + 2(k-1) = k(k-1). It’s about proving that n people take n(n-1) introductions to introduce themselves to each other.
Instructor’s Pet Peeve: When you establish the basis step, do not start that proof by saying 0 = 1(1-1). If you do that, you’re starting by assuming what you intend to prove. Instead, as with equivalence proofs, start from one side and work to the other. (As always, though, do whatever works in scratch work!)
Worked Proof: Sums of Powers of 2
Insight: The sum of the first n powers of 2 is the sum of the first n-1 powers of 2 plus 2n.
Theorem: The sum of the first n powers of 2 is 2n+1 - 1, for all non-negative integers n. That is:
Proof:
Basecase:For n = 0:
Inductive hypothesis: Assume for an arbitrary non-negative integer k that.
Inductive step:Under this assumption, we need to prove that .
Starting from the left hand side and breaking out the last term:
Then, using the induction hypothesis on the sum on the right:
Finally, using arithmetic:
This concludes our inductive proof. Therefore, the sum of the first n powers of 2 is 2n+1 - 1.
QED
Common CS Thing to Do: Is 0 the base case that you’d imagine? Would you start with 1 instead? Computer Scientists (and Mathematicians... and now you!) like to start with the 0 case here, mostly just because it works out fine. The sum from n = 0 up to 0 is just a single term where n=0. (By the way, the sum from n = 0 up to -1 is a sum with no terms, which equals 0 by definition.)
Instructor’s Pet Peeve, Part 2: Just as with the basis step, do not start your inductive step by saying: . That’s what you’re trying to prove. As with a logical equivalence proof, start from one side and work to the other. (In this proof, however, there is no context. The mathematical formula really is what you want to prove.)
Worked Proof: Maximum Nodes Per Height for a Binary Tree
Definitions:A binary tree is either an empty tree or a “root” node with two subtrees.[1] The height of an empty binary tree is -1.[2] The height of a non-empty binary tree is one more than the maximum of its two subtrees’ heights. (So, for non-empty trees, the height is the longest path from the tree’s root to a node with no children). n(h) is the maximumnumber of nodes in a binary tree of height h.
Theorem: n(h) = 2h+1 - 1. (In other words, a binary tree can contain an exponential number of nodes.)
Proof: (by induction on the size (number of nodes) in the tree)
Basecase:An empty tree has 0 nodes and height -1 by definition.So, n(-1) = 0 = 1-1 = 20-1 = 2-1+1-1.
InductiveHypothesis:Consider an arbitrary non-empty tree with as many nodes as it can have for its height. We’ll call the tree T and its height k. Note: we know T’s subtrees contain as many nodes as they can for their height; else, we could add nodes to them and increase T’s number of nodes (but T has as many nodes as it can for its height).
Assume for T’s two subtrees with heights k1 and k2that n(k1) = 2k1+1-1 and n(k2) = 2k2+1-1 (since each subtree contains as many nodes as it can for its height). (We can make this assumption because each subtree has at least 0 nodes by definition but fewer than T because it doesn’t include T’s root node.)
Inductive step:Under this assumption, we need to prove that T has 2k+1 - 1 nodes.
By definition, k = max(k1, k2) + 1. T contains its root node and all of its subtrees’ nodes, a total of 1 + n(k1) + n(k2) nodes. If k1 and k2 were not equal, we could increase the number of nodes in T without increasing its height by increasing the height of the shorter tree. (Because increasing, e.g., k1 only increases n(k1) = 2k1+1 - 1.) So, k1 = k2.
Thus, n(k) = 1 + n(k1) + n(k1), and k = k1 + 1. Rearranging, k1 = k - 1. And so we show:
n(k)= 1 + n(k1) + n(k1)
= 1 + 2n(k1)
= 1 + 2(2k1+1 - 1)[by the IH]
= 1 + 2(2k-1+1 - 1)[by the formula above]
= 1 + 2(2k-1+1) - 2
= 2k+1 - 1
This concludes our inductive proof. Therefore the maximum number of nodes in any binary treeof height h is 2h+1 - 1. QED
Why “strong induction” and “weak induction” (and “structural induction”) don’t matter: We never mentioned whether we used strong or weak induction here. Instead, we noticed that a binary tree that’s not empty has two subtrees and just assumed that our property holds for those subtrees. We’re safe to do that if the subtrees don’t “overshoot” our base case (which they don’t because they cannot have fewer than zero nodes) and really are “smaller than” our inductive case (which they are because no matter how large they are, neither one can possibly include the root node of the larger tree).
Never worry about whether you’re using strong or weak induction until you’ve figured out how to break the problem down. Once you figure out how to break it down, just assume your theorem holds for whatever smaller problems you found.
(Conversely, if we tell you to use weak induction on a problem, what we’re really telling you is that problems of size n break down naturally into problems of size n-1. If we tell you to use strong induction, we’re really telling you that problems of size n do not break down naturally into problems of size n-1 alone. They either break into smaller subproblems or into multiple-size subproblems.)
Instructor’s Pet Peeve, Part 3: This doesn’t really fit here, but there’s space on the page! We don’t need you to define the property you want to prove as P(n) for some positive (or non-negative, or whatever) integer n, but you generally can. In fact, you can define P(n) to be anything you want. For example, you could define P(n) = 2n+1 - 1. If you do define P(n) that way, however, then it’s equal to some number and is NOT A PREDICATE. For example, with this definition, P(4) = 31. That means you absolutely cannot go on to say “assume P(n) is true”. Why not? You tell me: is 31 true or false?
If you want to be able to say “assume P(n) is true”, then define it to be a predicate: something that is either true or false, given a value for n. In this case, you might define P(h) n(h) = 2h+1 - 1. That is either true or false, depending on whether the left side really does equal the right.
Proof Critique: All Horses Are the Same Colour
What’s wrong with this proof? Anything?
Theorem: All horses are the same colour.
Proof:
Basecase:All horses in any group of one horse are obviously the same colour.
Inductive hypothesis: Assume that all horses in any group of size k-1 are the same colour (for an arbitrary integer k ≥ 2).
Inductive step:Under this assumption, we need to prove that all horses in any group of horses of size k are the same colour.
Consider an arbitrary group of k horses.
Remove any one horse from it. What remains is a group of k-1 horses, which are all the same colour by the inductive hypothesis. Only the set-aside horse may be a different colour.
Now, return the horse to the group and remove a different horse. Again, the remaining horses are all the same colour, but from the previous step we already know that this time the set-aside horse is also the same colour. Therefore, all horses in any group of size k are the same colour.
This concludes our inductive proof. Therefore all horses in any group of any size are the same colour, i.e., all horses are the same colour.
QED
Worked Proof: Binary Search
Definitions: A listahas a length len(a). The indexes of the list in order are 0, 1, 2, ..., len(a) - 1.
Theorem: We can correctly search a sorted list of names by binary search:
Algorithm to search a list a of length len(a) for the name n:
If len(a) is 0, the name was not found; otherwise, check the element len(a)/2 and:
(1)If element len(a)/2 is the one sought; report it, and we’re done.
(2)If element len(a)/2 is larger than the one sought, repeat the algorithm on the list of elements 0, ..., len(a)/2 - 1.
(3)Otherwise (element len(a)/2 is smaller than the one sought), repeat the algorithm on the list of elements len(a)/2 + 1, ..., len(a) - 1.
Proof:
Basecase:A list of length 0 contains no names; so, the algorithm correctly reports failure.
Inductive hypothesis: Consider an arbitrary list L with at least one name. Assume that we can correctly search a sorted list of names by binary search for any list with length smaller than len(L).
Inductive step:Under this assumption, we show that we can correctly search a sorted list of names of length len(L) by binary search.
Since len(L) > 0, the algorithm will check on element len(L)/2 (which is in the list, since it must be at least 0 and cannot be as large as len(L)).
There are then three cases:
(1)The algorithm finds the name sought, in which case it correctly reports it.
(2)Element len(L)/2 is too large. Since the list is sorted, the name sought either isn’t in the list or is in the left portion of the list , and the algorithm does proceed on the left portion of the list. That sublist contains at least one fewer elements than L (because we eliminated element len(L)/2 ); so, it is shorter than L. By the IH, the algorithm operates correctly on this sublist.
(3)Element len(L)/2 is too small. Again, since the list is sorted, the name either isn’t in the list or is in the right portion of the list, and the algorithm proceeds on the right portion of the list. As above, that sublist is shorter than L. By the IH, the algorithm operates correctly.
This concludes the proof. Thus, we can correctly search a sorted list of names by binary search.
QED
Induction follows self-referential structure: Once again, we have a definition that refers to itself, and our inductive proof just follows that structure! Where’s the insight? In the algorithm’s definition!
Proof Critique: All Integers Greater than or Equal to Two Are Even
What’s wrong with this proof? Anything?
Theorem: All integers greater than or equal to two are even.
Proof:
Basecase: There exists an integer k=1 such that 2*k = 2. Therefore, two is even.
Inductive hypothesis:Assume that all integers i where 2 ≤ ikare even (for an arbitrary integer k 2).
Inductive step:Under this assumption, we need to prove that k is even.
We know that: k = (k-2)+2.
By the inductive hypothesis, k-2 is even. So, there is an integer j’ such that k-2 = 2*j’.
Since k = (k-2)+2, then k = 2*j’ + 2 = 2*(j’ + 1)
j’ + 1 is also an integer.
Therefore k is even.
This concludes our inductive proof. Therefore all integers greater than or equal to two are even.
QED
WARNING HINTS TO CRITIQUES ON THE NEXT PAGE!
Hint for horses the same colour: Does our inductive step really work. Is there anything misleading about the picture? Try a few cases. Start, as always, with the simplest or most interesting ones!
Hint for even numbers: Did we “overshoot” our base case?
BTW, proofs like the even numbers proof are part of the reason I stress assuming what you need, not worrying about strong vs. weak induction. It’s easy to look at the strong inductive hypothesis on the even numbers proof and say “gosh, that must have all my bases covered”. But, if you assume only what you need (that the theorem works for k-2), it becomes clearer why the proof doesn’t work at all.
[1] We assume no tree is a subtree of itself; so, the subtrees are smaller than the tree, which is handy for induction!
[2] The real goal of this -1 is to make the height of a tree with one node equal to 0.