***Huffman Coding*** Create a Python script that: -Reads a text file and determines the frequencies of all printable ASCII characters (32-126 and 10 in ASCII sequence) including line-feeds. -Create a Huffman Algorithm to compute all of the characters into bits in the printable ASCII characters. -Create an output file that looks like this: 'ASCII Position' 10 'Huffman Code' 1001
Added by Kevin S.
Close
Step 1
Read the text file and determine the frequencies of all printable ASCII characters (32-126) and line-feeds (10) in ASCII sequence. To do this, we can use a dictionary to store the frequencies of each character. We will iterate through the text file, count the Show more…
Show all steps
Your feedback will help us improve your experience
Chandra Jain and 82 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Encode the following text using Huffman coding: 84KZFZ48PUZZUPKFPFP8 Use the following steps: 1. Construct the frequency table. 2. Construct the Huffman table. 3. Assign codewords to each symbol. 4. Write the encoded bit-stream. 5. Decode the bitstream and verify that it is the same as the input. Using the above, fill in the blanks below: There are _____ bits in the encoded bit-stream. The average number of bits per symbol is _____. To encode the text using ASCII codes would require _____ bits in total.
Sri K.
Huffman Codes: Construct a Huffman code for the following data: character probability 0.1 0.1 0.2 0.15 0.15 Encode the text ABACABAD using the code of question a Decode the text whose encoding is 100010111001010 in the code of question a
Akash M.
Encode the following text using Huffman coding: OOVHA2OHH22VVOV2O2AV. Use the following steps: a. Construct the frequency table. b. Construct the Huffman tree. c. Assign codewords to each symbol. d. Write the encoded bit-stream. e. How many bits are in the encoded bit-stream?
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD