[10 points] Prof. Flashbulb proposed the following greedy
algorithm for solving the all-interval scheduling problem (aka
interval coloring, section 4.1): apply the greedy algorithm for
interval scheduling from the earlier part of section 4.1; give all
of those intervals one color, remove them from consideration, and
recursively apply the same method to the resulting reduced set of
intervals. Does this method does give an optimal solution to the
problem? Either prove it or give a simple counterexample and
explain why your counter example is a counter example.
[10 points]
A quick look at the algorithm on page 124 for the all-intervals
scheduling problem suggests an O(n2) time bound: an
outer loop for j = 1, ..., n, and an implicit inner loop "for each
interval Ii" that also seems to need order n time.
- Give a slightly more detailed description of an
implementation of this algorithm that will take only O(dn) time,
where d is the depth of the problem instance (pg 123).
(For your timing analysis, ignore the Theta(n log n) time for
the initial step that sorts the intervals by start time.)
- If d is small, the above method typically will be much faster
than the simple O(n2) analysis suggests. Show,
however, that it is not faster in the worst case. I.e.,
show that there are instances where it takes time
Omega(n2). [Note that to show a lower bound like
this, it's not good enough to show one bad example; you really
need to show that there are infinitely many bad examples, for
larger and larger values of n.]
- Give a more clever implementation of the algorithm whose
running time is O(n log n), (independent of depth) and justify
this time bound. [Hint: use a priority queue.]
[10 points] Chapter 4, Page 190, Problem 5.
[10 points] Chapter 4, Page 191, Problem 6.
[10 points] Chapter 4, Page 194, Problem 13.
[10 points] Chapter 4, Page 198, Problem 19.
[10 points]
- Simulate the Huffman tree algorithm on the input alphabet
a, b, c, d, e with frequencies .15, .30, .50, .02, .03, resp.
Show the intermediate "trees" built by the algorithm, as well
as the final tree.
- What will be the total length in bits of the compressed
text built from a sequence of 100 letters having the
above frequencies using the Huffman code you calculated?
- Suppose I tell you that the frequencies of a and b are .15, .30,
resp, as above, but I don't tell you the other frequencies. I
can quickly tell (e.g., without running the full
Huffman algorithm) that the Huffman code for this data is
not the one shown in figure 4.16 (a) (pg 168). Explain
how.
[10 points] Suppose you break a file into 8 bit characters and
find that all 256 combinations are present, with the most frequent
occuring less that twice as often as the least frequent. Prove that
the Huffman code for this data will not result in a shorter file.