=========================================================================== CSC 236 Sample Solutions for Week 3 Tutorial Fall 2007 =========================================================================== A. Make a conjecture about the values of n for which n^2 <= 2^n. Prove your conjecture. Explore: Compute table of values for n^2 and 2^n for small n. Conjecture: n^2 <= 2^n for all n >= 4. 0. Define P(n): n^2 <= 2^n. 1. Base Case: Prove P(4): 4^2 <= 2^4. 4^2 = 16 = 2^4 Hence, P(4). 2. Ind. Hyp.: Let n >= 4 and suppose P(n): n^2 <= 2^n. 3. Ind. Step: Prove P(n+1): (n+1)^2 <= 2^{n+1}. (n+1)^2 = n^2 + 2n + 1 <= 2^n + 2n + 1 (by IH) Q: What next? What would help us conclude what we want? A: If we knew 2n + 1 <= 2^n. Q: How could we prove this? A: Idea: maybe show 2n + 1 <= n^2 and use IH. Q: What do we know about n that could help? A: n >= 4 (from IH). 2n + 1 <= 2n + n = 3n <= n*n = n^2, because n >= 4, so continuing with our reasoning: (n+1)^2 <= 2^n + 2n + 1 <= 2^n + n^2 (by the argument just given) <= 2^n + 2^n = 2^{n+1} (by IH). Hence, P(n+1). 4. Conclusion: By induction, \-/ n >= 4, P(n), i.e., n^2 <= 2^n for all n >= 4. B. When computing the product of n distinct real numbers a_1 a_2 ... a_n, there are many ways to order the multiplication operations that have to be performed. For example, the product of a_1 a_2 ... a_5 could be computed in the order (a_1 * a_2) * ((a_3 * (a_4 * a_5)), or in the order a_1 * ((a_2 * (a_3 * a_4)) * a_5), or in many other ways. Make a conjecture about the number of multiplication operations required to compute the product a_1 a_2 ... a_n of n distinct real numbers, for any n -- in particular, does this number depend on the order of the multiplications? Prove your conjecture. Conjecture: For all n >= 1, it takes exactly n-1 operations to compute the product of any n numbers, no matter how it is parenthesized. 0. Define P(n): It takes exactly n-1 operations to compute the product of any n numbers, no matter how it is parenthesized. Q: What form of induction should we use? A: Either would work! Let's practice complete induction -- simple induction will be mentioned at the end. Complete induction version Q: How do we know whether we should start with base cases? A: Are there any values of n for which we cannot conclude P(n) from the fact that P(k) for all k < n? 1. Base Case: Prove P(1): it takes 0 operation to compute the product of any one number. This is trivially true, so P(1). 2. Ind. Hyp.: Let n > 1 {since we've already proved P(1) and we're about to try to prove P(n)} and suppose \-/ k in {1,...,n-1}, P(k), i.e., for 1 <= k < n, it takes exactly k-1 operations to compute the product of any k numbers, no matter how it is parenthesized. 3. Ind. Step: Prove P(n): it takes exactly n-1 operations to compute the product of any n numbers, no matter how it is parenthesized. Since n > 1 (by IH), we have to perform at least one operation to compute the product of a_1 ... a_n. Consider the *last* operation performed: (a_1 ... a_i) (a_{i+1} ... a_n), for some 1 <= i < n. By the IH, it takes i-1 operations to compute the product of a_1 ... a_i, and it takes n-i-1 operations to compute the product of a_{i+1} ... a_n (since 1 <= i < n -> n-1 >= n-i > 0 so the IH applies to a_{i+1} ... a_n). Hence, it takes 1 + i-1 + n-i-1 = n-1 operations to compute the product a_1 ... a_n. Since we considered arbitrary ways to compute the product a_1 ... a_n, P(n) holds. 4. Conclusion: For all n >= 1, P(n), i.e., it takes exactly n-1 operations to compute the product of n numbers, no matter his it is parenthesized. Simple induction version - Main idea of inductive step: Consider the product a_1 ... a_{n+1}. For some pair of adjacent numbers a_i a_{i+1}, 1 <= i <= n, perform an operation to multiply them: a_i * a_{i+1} = a'_i. The rest of the product looks like a_1 ... a_{i-1} a'_i a_{i+2} ... a_{n+1}, and it consists of n numbers so by the IH, it will take n-1 operations to compute it. Together with the first operation, this adds up to n operations, as required. - Easy exercise: write this up formally -- ask during office hours if you want to double-check your answer.