Path: blob/master/Programming Assignment 3/HuffmanCoding.ipynb
423 views
Huffman Coding
1 point
1.In this programming problem and the next you'll code up the greedy algorithm from the lectures on Huffman coding.
Download the text file below.
huffman.txt This file describes an instance of the problem. It has the following format:
[number_of_symbols]
[weight of symbol #1]
[weight of symbol #2]
...
For example, the third line of the file is "6852892," indicating that the weight of the second symbol of the alphabet is 6852892. (We're using weights instead of frequencies, like in the "A More Complex Example" video.)
Your task in this problem is to run the Huffman coding algorithm from lecture on this data set. What is the maximum length of a codeword in the resulting Huffman code?
ADVICE: If you're not getting the correct answer, try debugging your algorithm using some small test cases. And then post them to the discussion forum!
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-64-d3c59e406f60> in <module>()
1 # test
----> 2 test_dict2 = {[[2],[3]]: [0], [[3],[5]]: [1]}
3 for i, j in enumerate(test_dict2):
4 test_dict2[i[0]] = j.extend([0])
5 test_dict2[i[1]] = j.extend([1])
TypeError: unhashable type: 'list'
Question 1 answer
19
1 point 2.Continuing the previous problem, what is the minimum length of a codeword in your Huffman code?
Question 2 answer
9