 
Summary: CS5050 Homework 7 Chapters 12 and 13
1. (C12.8) Let S be a set of n intervals of the form [a,b] where a < b. Design an efficient data structure that
can answer, in O(log n +k ) time, queries of the form contains(x), which asks for a list of all intervals in S
which contain x. k is the number of such intervals. What is the space usage of your data structure? [Notice
that other than finding a place to begin searching, you are not allowed to paw through lots of intervals that
aren't ones you select. If this wasn't a concern, lots of things would work.]
2. Jennie and Ben have found a treasure chest. They have a bag of valuables and want to divide it up. For each
of the following scenarios, either give a polynomialtime algorithm to divide up the money, or prove that the
problem is NPcomplete. The input in each case is a list of n items in the bag, along with their value. If the
problem is polynomial, you demonstrate that by showing me a polynomial time algorithm to solve it. If
the problem is NPcomplete, you demonstrate that fact with a mapping from a known NPcomplete
problem.
a. There are n coins, but only 2 different denominations: Gobbles and Hortz. Gobbles are worth x dollars,
and Hortz are worth y dollars. They wish to divide the coins so the money is divided exactly evenly.
b. There are n coins with m different denominations, but each denomination is a nonnegative integer
power of 2, i.e., the possible denominations are 1 dollar, 2 dollars, 4 dollars, etc. They wish to divide
the money exactly evenly.
c. There are n checks, which are, amazingly enough, all made out to "Cash." They wish to divide the
checks (not just cash them all and divide the money) so that they each get the exact same amount of
money.
