Discrete Mathematics and Its Applications, 8th Edition
Discrete Mathematics and Its Applications, 8th Edition
else return =y
x :
what the if clause does. Inductive step: Fix k > 0, assume x :=1
the inductive hypothesis—that the algorithm works correctly y :=3
for all values of its first argument less than k—and consider z := 5
what happens with input (k, b), where k < b. Because k > 0, for i := 1 to n * 2
recursively computes the product of k + 1 * 1 = k and x, 37. procedure reverse(w: bit string)
rithm works correctly for input k. Then for input k + 1, it last character followed by the reversal of its first n * 1 char-
gives as output (because of the else clause) its output when acters (see Exercise 37 in Section 5.3), the algorithm behaves
the input is k, plus 2(k + 1 * 1) + 1. By the inductive correctly when n > 0 by the inductive hypothesis. 41. The
2
hypothesis, its output at k is k , so its output at k + 1 is algorithm implements the idea of Example 14 in Section 5.1.
k
2
+ 2(k + 1 * 1) + 1 = k
2
+ 2k + 1 = (k + 1) 2
, as desired. If n = 1 (basis step), place the one right triomino so that its
× 2 board. If n > 1,
n
25. n multiplications versus 2 27. O(log n) versus n
armpit corresponds to the hole in the 2
29. procedure a(n: nonnegative integer) then divide the board into four boards, each of size 2
* ×2 * ,
n 1 n 1
if n= 0 then return 1 notice which quarter the hole occurs in, position one right tri-
else if n= 1 then return 2 omino at the center of the board with its armpit in the quarter
else return a(n * 1) ⋅ a(n * 2)
where the missing square is (see Figure 7 in Section 5.1), and
31. Iterative
invoke the algorithm recursively four times—once on each of
*1 *1
33. procedure iterative(n: nonnegative integer) the 2
n
×2 n
boards, each of which has one square missing