This preview shows page 1. Sign up to view the full content.
Unformatted text preview: nction of the size of the input.
It is common to refer to an algorithm such as our knapsack dynamic programming algorithm as being a pseudopolynomial time algorithm, for its running time
depends on the magnitude of a number given in the input, not its encoding size. In
practice, such algorithms should run much faster than any bruteforce algorithm,
but it is not correct to say they are true polynomialtime algorithms. In fact, there is
a theory known as NPcompleteness, which is discussed in Chapter 13, that states
that it is very unlikely that anyone will ever ﬁnd a true polynomialtime algorithm
for the 01 knapsack problem.
Elsewhere in this book, we give additional applications of the dynamic programming technique for computing reachability in a directed graph (Section 6.4.2)
and for testing the similarity of two strings (Section 9.4). Chapter 5. Fundamental Techniques 282 5.4 Exercises
Reinforcement
R5.1 Let S = {a, b, c, d , e, f , g} be a collection of objects with beneﬁtweight values
as follows: a: (12, 4), b: (10, 6), c: (8, 5), d : (11, 7), e: (14, 3), f : (7, 1), g: (9, 6).
What is an optimal solution to the fractional knapsack problem for S assuming
we have a sack that can hold objects with total weight 18? Show your work.
R5.2 Describe how to implement the TaskSchedule method to run in O(n log n) time.
R5.3 Suppose we are given a set of tasks speciﬁed by pairs of the start times and ﬁnish
times as T = {(1, 2), (1, 3), (1, 4), (2, 5), (3, 7), (4, 9), (5, 6), (6, 8), (7, 9)}. Solve
the task scheduling problem for this set of tasks.
R5.4 Characterize each of the following recurrence equations using the master method
(assuming that T (n) = c for n < d , for constants c > 0 and d ≥ 1).
a. T (n) = 2T (n/2) + log n
b. T (n) = 8T (n/2) + n2
c. T (n) = 16T (n/2) + (n log n)4
d. T (n) = 7T (n/3) + n
e. T (n) = 9T (n/3) + n3 log n
R5.5 Use the divideandconquer algorithm, from Section 5.2.2, to compute 10110011 ·
10111010 in binary. Show your work.
R5.6 Use Strassen’s matrix multiplication algorithm to multiply the matrices
X= 3
4 2
8 and Y= 15
96 . √
R5.7 A complex number a + bi, where i = −1, can be represented by the pair (a, b).
Describe a method performing only three realnumber multiplications to compute
the pair (e, f ) representing the product of a + bi and c + d i.
R5.8 Boolean matrices are matrices such that each entry is 0 or 1, and matrix multiplication is performed by using AND for · and OR for +. Suppose we are given two
n × n random Boolean matrices A and B, so that the probability that any entry
in either is 1, is 1/k. Show that if k is a constant, then there is an algorithm for
multiplying A and B whose expected running time is O(n2 ). What if k is n?
R5.9 What is the best way to multiply a chain of matrices with dimensions that are
10 × 5, 5 × 2, 2 × 20, 20 × 12, 12 × 4, and 4 × 60? Show your work.
R5.10 Design an efﬁcient algorithm for the matrix chain multiplication problem that
outputs a fully parenthesized expression for how to multiply the matrices in the
chain using the minimum number of operations.
R5.11 Solve Exercise R5.1 for the 01 knapsack problem.
R5.12 Sally is hosting an Internet auction to sell n widgets. She receives m bids, each
of the form “I want ki widgets for di dollars,” for i = 1, 2, . . . , m. Characterize
her optimization problem as a knapsack problem. Under what conditions is this
a 01 versus fractional problem? 5.4. Exercises 283 Creativity
C5.1 A native Australian named Anatjari wishes to cross a desert carrying only a single water bottle. He has a map that marks all the watering holes along the way.
Assuming he can walk k miles on one bottle of water, design an efﬁcient algorithm for determining where Anatjari should reﬁll his bottle in order to make as
few stops as possible. Argue why your algorithm is correct.
C5.2 Consider the single machine scheduling problem where we are given a set T
of tasks speciﬁed by their start times and ﬁnish times, as in the task scheduling
problem, except now we have only one machine and we wish to maximize the
number of tasks that this single machine performs. Design a greedy algorithm
for this single machine scheduling problem and show that it is correct. What is
the running time of this algorithm?
C5.3 Describe an efﬁcient greedy algorithm for making change for a speciﬁed value
using a minimum number of coins, assuming there are four denominations of
coins (called quarters, dimes, nickels, and pennies), with values 25, 10, 5, and 1,
respectively. Argue why your algorithm is correct.
C5.4 Give an example set of denominations of coins so that a greedy change making
algorithm will not use the minimum number of coins.
C5.5 In the art gallery guarding problem we are given a line L that represents a long
hallway in an art gallery. We are also given a set X = {x0 , x1 , . . . , xn−1 } of real
numbers that specify the positions of paintings in this hallway. Suppose that a
single g...
View
Full
Document
This document was uploaded on 03/26/2014.
 Spring '14

Click to edit the document details