辅导Huffman code 、辅导python Huffman code 代码
- 首页 >> Python编程Encoder (Compression)
•Write a program that constructs a Huffman code for a given text and encode it.
•Specify your assumptions, data structure used in the implementation.
•Your program should prompt the user to enter the names of the text file and compressed file. Figure 1 shows a sample of the output where the user’s inputs are printed in bold.
Figure 1
• Hint: You may implement the Huffman’s encoder based on the following steps:
o Build a frequency chart for all characters in your text. o Build a Huffman tree. o Make a list of all codewords. o Encode your text using the list of codewords.
Decoder (Decompression)
•Write a program for decoding a text which has been encoded with a Huffman code.
•Specify your assumptions, data structure used in the implementation.
•Your program should prompt the user to enter the names of the compressed file and decoded text file. Figure 2 shows a sample of the output where the user’s inputs are printed in bold.