Beruflich Dokumente
Kultur Dokumente
Solutions to Exercise 2
Hwa-You Hsu
December 1, 2003
Exercise 16.4-4
30%
Let S be a finite set and let S1, S2, , Sk be a partition of S into nonempty disjoint
subsets. Define the structure (S, l) by the condition that l = {A:|ASi| 1 for i = 1,
2, , k}. Show that (S, l) is a matroid. That is, the set if all sets A that contain at most
one member in each block of the partition determines the independent sets of a
matroid.
Solution
Recall the definition of matroid:
A matroid is a ordered pair M = (R, I) satisfying the definitions:
1. R is a finite nonempty set.
2. I is hereditary: I is a nonempty family of subsets of R, called the independent
subsets of R, such that if BI and AB, then AI, obviously, I
3.
M satisfies the exchange property: If AI, BI and |A|<|B|, then xB-A such
that A{x}I
optimal choice uses at least 5 pennies, we can turn it to a nickel and use fewer
coins. Otherwise, if the optimal solution uses at most 2 dimes, it must use enough
pennies to make up at least 25 cents, and we can turn it to a quarter and use fewer
coins. Otherwise, the optimal solution uses at least 3 dimes, we can turn it to a
quarter and a nickel and use fewer coins.
Therefore the greedy choice property is satisfied.
b. The proof is similar to a), we will show optimal substructure here.
Suppose we have n cents to change, cinci+1, 1ik. If the optimal solution
replaces a ci coins (1ac) and [optimal denomination of (n - a ci)], by picking
ac ci-1 coins and [optimal denomination of (n - a ci)]. But obviously, the numbers
of coins to pick are increased, which is not a optimal solution. By contradiction,
the optimal substructure property is proved.
c. Using a set of coins consisting of 8-cent, 6-cent and 1-cent to denominate 12 cents.
Greedy algorithm will give the solution (8, 1, 1, 1), total 5 nickels, but the optimal
solution is (6, 6).
d. As shown in part a), the problem has the optimal substructure property. So we
formulate a Dynamic Programming recursion. Let n[i, j] represent the minimum
number of coins required to make change for j cents using coins with
denomination no greater than ci (c0 = 1). Then
n[0, j] = j
n[i, j] = min( n[i-1, j], n[i, j-ci] + 1) (either do not use coin ci or use the minimum
number of coins to make change for j- ci cents plus 1 for ci ).
We can calculate the value of n[i, j] in O(nk) time.
To reconstruct the values of each coin in the change set by checking
whether n[i, j] = n[i-1, j] or n[i, j] = n[i, j-ci] + 1 in O(k+n) time.
Exercise 17.4-3
30%
Suppose that instead of contracting a table by halving its size when its load factor
drops below 1/4, we contract it by multiplying its size by 2/3 when its load factor
drops below 1/3. Using the potential function
(T ) = 2 num [T ] size [T ] ,
show that the amortized cost of a TABLE-DELETE that uses this strategy is bounded
above by a constant.
Solution
Suppose that i-th operation is TABLE_DELETE, consider the value of load factor:
i= (number of entries in table after iteration i) / (size of table after iteration i) =
numi/sizei
case 1. Ifi-1 = 1/2, i1/2