Chapter 8: Q1E (page 535)
How many comparisons are needed for a binary search in a set of 64 elements?
Short Answer
The number of comparisons needed is 14.
Chapter 8: Q1E (page 535)
How many comparisons are needed for a binary search in a set of 64 elements?
The number of comparisons needed is 14.
All the tools & learning materials you need for study success - in one app.
Get started for freeIn this exercise we construct a dynamic programming algorithm for solving the problem of finding a subset S of items chosen from a set of n items where item i has a weight , which is a positive integer, so that the total weight of the items in S is a maximum but does no exceed a fixed weight limit W. Let denote the maximum total weight of the items in a subset of the first j items such that this total weight does not exceed w. This problem is known as the knapsack problem.
a) Show that if, then
b) Show that if , then.
c) Use (a) and (b) to construct a dynamic programming algorithm for determining the maximum total weight of items so that this total weight does not exceed W. In your algorithm store the values as they are found.
d) Explain how you can use the values computed by the algorithm in part (c) to find a subset of items with maximum total weight not exceeding W.
Use Exercise 29 to show that if , then is .
How many ternary strings of length six do not contain two consecutiveor twoconsecutive?
Find a closed form for the generating function for each of these sequences. (Assume a general form for the terms of the sequence, using the most obvious choice of such a sequence.)
a) \( - 1, - 1, - 1, - 1, - 1, - 1, - 1,0,0,0,0,0,0, \ldots \)
b) \(1,3,9,27,81,243,729, \ldots \)
c) \(0,0,3, - 3,3, - 3,3, - 3, \ldots \)
d) \(1,2,1,1,1,1,1,1,1, \ldots \)
e) \(\left( {\begin{array}{*{20}{l}}7\\0\end{array}} \right),2\left( {\begin{array}{*{20}{l}}7\\1\end{array}} \right),{2^2}\left( {\begin{array}{*{20}{l}}7\\2\end{array}} \right), \ldots ,{2^7}\left( {\begin{array}{*{20}{l}}7\\7\end{array}} \right),0,0,0,0, \ldots \)
f) \( - 3,3, - 3,3, - 3,3, \ldots \)
g) \(0,1, - 2,4, - 8,16, - 32,64, \ldots \)
h) \(1,0,1,0,1,0,1,0, \ldots \)
Letbe the sequence of Catalan numbers, that is, the solution to the recurrence relationwith.
(a)Show that ifis the generating function for the sequence of Catalan numbers, then. Conclude (using the initial conditions) that.
(b) Use Exercise 40 to conclude that so that
(c) Show thatfor all positive integers.
What do you think about this solution?
We value your feedback to improve our textbook solutions.