This preview shows pages 1–5. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: 4. a) P(18) is true, because we can form 18 cents of postage with one 4—cent stamp and two 7—cent stamps.
P(19) is true, because we can form 19 cents of postage with three 4—cent stamps and one 7—cent stamp. P(20)
is true, because we can form 20 cents of postage with ﬁve 4-cent stamps. P(21) is true, because we can form
20 cents of postage with three 7—cent stamps. b) The inductive hypothesis is the statement that using just 4—cent and 7—cent stamps we can form j cents
postage for all j with 18 g j S k, where we assume that k 2 21. c) In the inductive step we must show, assuming the inductive hypothesis, that we can form k + 1 cents
postage using just 4—cent and 7—cent stamps. ' d) We want to form k + 1 cents of postage. Since k 2 21, we know that P(k — 3) is true, that is, that we
can form It — 3 cents of postage. Put one more 4—cent stamp on the envelope, and we have formed k + 1 cents
of postage, as desired. 6) We have completed both the basis step and the inductive step, so by the principle of strong induction, the ,
statement is true for every integer n greater than or equal to 18. .8. Since both 25 and 40 are multiples of 5, we cannot form any amount that is not a multiple of 5. So let’s
determine for which values of n we can form 571 dollars using these gift certiﬁcates, the ﬁrst of which provides
5 copies of $5, and the second of which provides 8 copies. We can achieve the following values of n: 5 = 5,
8 = 8,10 = 5+5,13 = 8+5,15 = 5+5+5, 16 = 8+8,18 = 8+5+5, 20 = 5+5+5+5+5, 21 = 8+8+5,
23=8+5+5+5, 24=8+8+8, 25: 5+5+5+5+5, 26=8+8+5+5, 28=8+5+5+5+5,
29 = 8+8+8+5, 30 - 5 : 5+5 I 5+5 I 5, 31 — 8+8+5+5+5, 32=8+8+8+8. By having
considered all the combinations, we know that the gaps in this list cannot be ﬁlled. We claim that we can form total amounts of the form 571 for all n 2 28 using these gift certiﬁcates. (In other words, $135 is the
largest multiple of $5 that we cannot achieve.) To prove this by strong induction, let P(n) be the statement that we can form 5n dollars in gift certiﬁcates
usmg Just 25-dollar and 40—dollar certiﬁcates. We want to prove that P(n) is true for all n 2 28. From our work above, we know that P(n) is true for n z 28, 29, 30, 31, 32. Assume the inductive hypothesis, that P(j)
is true for all j with 28 S j S k, where k is a ﬁxed integer greater than or equal to 32. We want to show
that P09 + 1) is true. Because k — 4 Z 28, we know that P(k — 4) is true, that is, that we can form 5(k — 4)
dollars. Add one more $25-dollar certiﬁcate, and we have formed 5(k + 1) dollars, as desired. 14. We prove this using strong induction. It is clearly true for n = 1, because no splits are performed, so the sum uted is 0, which equals n(n — 1) / 2 when n = 1. Assume the strong inductive hypothesis, and suppose u u . -
—i stones, where i is a posrtlve Integer less than n. ThlS that our ﬁrst splitting is into piles of 2' stones and n .
gives a product — The rest of the products will be obtained from splitting the plles thus formed, and so by the inductive hypothesis, the sum of the products will be — 1) / 2 + (n — (n —— i — 1) / 2. So we must showthat‘ H— 71—1. _i— n —1
i(n—i)+z(121)+‘L_17}2__L): (n2 ) no matter what 2' is. This follows by elementary algebra, and our proof is complete. 26. 30. 32. a) Clearly these conditions tell us that P01) is true for the even values of n, namely, 0, 2, 4, 6, 8, Also, it is clear that there is no way to be sure that P(n) is true for other values of n. b) Clearly these conditions tell us that P(n) is true for the values of n that are multiples of 3, namely, 0
3, 6, 9, 12, . . .. Also, it is clear that there is no way to be sure that P(n) is true for other values of n. 3 c) These conditions are sufﬁcient to prove by induction that P(n) is true for all nonnegative integers n. d) We immediately know that P(O), P(2), and P(3) are true, and clearly there is no way to be sure that
P(l) is true. Once we have P(2) and P(3), the inductive step P(n) —+, P(n + 2) gives us the truth of P(n)
for all n 2 2. ’ The ﬂaw comes, in the inductive step, where we are implicitly assuming that k 2 1 in order to talk about a,“1
in the denominator (otherwise the exponent is not a nonnegative integer, so we cannot apply the inductive
hypothesis). Our basis step was n = 0, so we are not justiﬁed in assuming that [C 2 1 when we try to prove
the statement for k + 1 in the inductive step. Indeed, it is precisely at n : 1 that the proposition breaks down. The proof is invalid for k = 4. We cannot increase the postage from 4 cents to 5 cents by either of the
replacements indicated, because there is no 3-cent stamp present and there is only one 4-cent stamp present.
There is also a minor ﬂaw in the inductive step, because the condition that j 2 3 is not mentioned. 9 4. a) f(2)=f(1)—f(0)=1—1:0,f(3):f(2)—f(1)'=0_1=_17f(4):f(3)_f(2):_1_0=-1,
b) Clearly H”) = 1 for all n, since 1.1: 1. W6. a) This is valid, since we are provided with the value at n = 0, and each subsequent value is determined by the previous one. Since all that changes from one value to the next is the Sign, we conjecture that f = (—1)".
This is true for n 2 0, since (—1)0 = 1. If it is true for n = k, then we have f(k +1) 2 —f(k +1 — 1):
—f(k) = —(—1)k by the inductive hypothesis, whence f(k —|— 1) = (—1)k+1. b) This is valid, since we are provided with the values at n = 0, 1, and 2, and each subsequent value is
determined by the value that occurred three steps previously. We compute the ﬁrst several terms of the
sequence: 1, 0, 2, 2, O, 4, 4, 0, 8, We conjecture the formula = 2"/3 when n E 0 (mod 3), = 0 when n E 1 (mod 3), f(n) = 2("+1)/3 when n E 2 (mod 3). To prove this, ﬁrst note that in the
base cases we have f(0) % 1 = 20/3, f(1) = 0, and f(2) = 2 : 2(2+1)/3. Assume the inductive hypothesis
that the formula is valid for smaller inputs. Then for n E 0 (mod 3) we have f(n) = 2f(n —3) = 2-2("_3)/3 =
2 ~ 271/3 - 2‘1 = 2W3, as desired. For n E 1 (mod 3) we have = 2f(n — 3) = 2-0 = 0, as desired. And
for n E 2 (mod 3) we have f(n) = 2f(n — 3) = 2 - 2("‘3+1)/3 = 2 - 2("+1)/3 - 2“1 = 2("+1)/3, as desired. c) This is invalid. We are told that f (2) is deﬁned in terms of f (3), but f (3) has not been deﬁned. 10. The base case is that Sm(0) = m. The recursive part is that Sm(n + 1) is the successor of 3mm) (i.e., the integer that follows Sm(n), namely Sm(n) + 1). 22. 32. 38. 58. 26. a) If we apply each of the recursive step rules to Clearly only positive integers can be in S, since 1 is a positive integer, and the sum of two positive integers is
again a positive integer. To see that all positive integers are in S, we proceed by induction. Obviously 1 E S.
Assuming that n E S, we get that n + 1 is in S by applying the recursive part of the deﬁnition with s = n
and t = 1. Thus S is precisely the set of positive integers. the only element given in the basis step, we see that (2, 3)
and (3, 2) are in S. If we apply the recursive step to these we add (4,6), (5, 5), and (6, 4). The next round
gives us (6,9), (7,8), (8,7), and (9,6). A fourth set of applications adds (8,12), (9,11), (10,10), (11,9),
and (12,8); and a ﬁfth set of applications adds (10,15), (11,14), (12, 13), (13,12), (14, 11), and (15,10). b) Let P(n) be the statement that 5 I a+b whenever (a, b) E S is obtained by n applications of the recursive
step. For the basis step, P(O) is true, since the only element of S obtained with no applications of the
recursive step is (0,0), and indeed 5 I 0 + 0. Assume the strong inductive hypothesis that 5 I a + b whenever
(a, b) 6 S is obtained by k or fewer applications of the recursive step, and consider an element obtained with
k + 1 applications of the recursive step. Since the ﬁnal application of the recursive step to an element (a, b)
must be applied to an element obtained with fewer applications of the recursive step, we know that 5 I a + b.
So we just need to check that this inequality implies 5 I a + 2 + b + 3 and 5 I a + 3 + b + 2. But this is clear,
since each is equivalent to 5 I a + b + 5, and 5 divides both a + b and 5. c) This holds for the basis step, since 5 I 0 + 0. If this holds for (a, b), then it also holds for the elements obtained from (a, b) in the recursive step by the same argument as in part a) 0nes()\) = O and 0nes(wx) = x + 0nes(w), where w is a bit string and m is a bit (viewed as an integer
when being added) , b) The basis step is when t = A, in which case we have ones(s)\) = ones(s) = ones(s)+0 ——— ones(s)+ones()\).
For the inductive step, write 25 2 war, where w is a bit string and a: is a bit. Then we have ones(s(wx)) =
ones((sw)m) = m + ones(sw) by the recursive deﬁnition, which is x + 0nes(s) + 0nes(w) by the inductive
hypothesis, Which is ones(5) + (a: + ones by commutativity and associativity of addition, which ﬁnally
equals 0nes(s) + ones(w;r;) by the recursive deﬁnition. There are two types of palindromes, so we need two base cases, namely A is a palindrome, and x is a
palindrome for every symbol .73. The recursive step is that if oz is a palindrome and a; is a symbol, then mom: is a palindrome. I a) This would be a proper deﬁnition if the recursive part were stated to hold for n 2 2. As it stands however
F(1) IS ambiguous, and F (0) is undeﬁned. 7 ’ b) This deﬁnition makes no sense as it stands; F (3) is not deﬁned, since F (0) isn’t. Also, F (2) is ambiguous. c) For n = ,3, the recursive part makes no sense, since we would have to know F (3/ 2). Also F (2) is‘
ambiguous. ’ d) The deﬁnition is ambiguous about n = 1, since both the second clause and the third clause seem to apply.
Thls would be a valid deﬁnition if the third clause applied only to odd n > 3. 10. The recursive algorithm works by comparing the last element with the maximum of all but the last. We l
assume that the input is given as a sequence. procedure macr(a1,a2, . . . ,an : integers) if n :1 then ma$(a1,a2, . . .,a,,) := (11 else begin
m 2: max(a1,a2, . . . ,an_1)
if m > an then ma$(a1,a2,...,an) := m
else maa:(a1,a2, . . . ,an) := an end The largest in a list of one integer is that one integer, and that is the answer the recursive algorithm gives
when n = 1, so the basis step is correct. Now assume that the algorithm works correctly for n :- k. If
n = k + 1, then the else clause of the algorithm is executed. First, by the inductive hypothesis, the algorithm
correctly sets m to be the largest among the ﬁrst It integers in the list. Next it returns as the answer either
that value or the (k + 1)st element, whichever is larger. This is clearly the largest element in the entire list.
Thus the algorithm correctly ﬁnds the maximum of a given list of integers. We use the hint. procedure twopower(n : positive integer, a : real number)
if n = 1 then twopower(n,a) := (12
else twopower(n, a) := twopower(n — 1,a)2 . We use the idea in Exercise 24, together with the fact that a" = (an/2)2 if n is even, and a" = a- (am—1V2)2
if n is odd, to obtain the following recursive algorithm. In essence we are using the binary expansion of n
implicitly. procedure fastpower(n : positive integer, a : real number)
if n = 1 then fastpower(n,a) := (1 else if n is even then fastpower(n,a) :2 fastpawer(71/2,a)2
else fastpower(n, a) := a ‘ fastpower((n —- 1)/2, a)2 44. The procedure is the same as that given in the solution to Example 9. We will show the tree and inverted tree that indicate how the sequence is taken apart and put back together. / \ K \.
/‘“\ /5\5 ‘/ \8 7/ \6
v x; v
\ 45/ \m/ 12345675 2. There are two cases. If x Z 0 initially, then nothing is executed, so as _>_ 0 at the end. If at < 0 initlauy, tnen
m is set equal to 0, so a: = 0 at the end; hence again a: Z 0 at the end. 12. Suppose that the initial assertion is true before the prOgram begins, so that a and d are positive integers. :
Consider the following loop invariant p: “a = dq + r and 7" Z 0 .” This is true before the loop starts, since the
equation then states a = d - 0 + a, and we are told that a (which equals 7" at this point) is a positive integer, ,
hence greater than or equal to 0. Now we must Show that if p is true and 'r 2 d before some pass through
the loop, then it remains true after the pass. Certainly we still have T Z 0, since all that happened to 'r was
the subtraction of d, and r 2 d to begin this pass. Furthermore, let q’ denote the new value of q and 7" the
new value of r. Then dq’ + r’ = d(q + 1) + (r — d) = dq + d+ r —' d = dq +7" = a, as desired. Furthermore, the
loop terminates eventually, since one cannot repeated subtract the positive integer d from the pesitive integer
7" without 7' eventually becoming less than d. When the loop terminates, the loop invariant p must still be
true, and the condition 7“ 2 d must be false——i.e., r < d must be true. But this is precisely the desired ﬁnal
View Full Document
This note was uploaded on 09/28/2011 for the course ECS 12 taught by Professor Khoel during the Spring '09 term at UC Davis.
- Spring '09