Assignment 9

Due Monday, 4/8/96.
  1. Construct a set of optimal Huffman codes for letters (a,b,c,d,e,f,g) with frequencies (4,5,7,8,10,12,20). Not to be handed in.
  2. Suppose that you have k sorted files with lengths l1, ..., lk. We know that it takes time O(m+n) to merge files of size m and n. Describe an algorithm to merge all k files in minimal time. The only operation available is to merge the files in pairs. E.g., if the files have lengths 30, 20, and 10, then merging the first two takes 50 units of time, then merging the result with the last file takes 60, for a total of 110 units of time. However, if you do the last two first and then merge the results of that with the first file, it will take 90 units of time altogether. Prove (by induction, of course) that your algorithm gives the solution in the optimal number of moves. Turn this problem in.