Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this assignment, you will implement Huffman Encoding. You will not actually do any compression. All you need to do is determine what the huffman
In this assignment, you will implement Huffman Encoding. You will not actually
do any compression. All you need to do is determine what the huffman codes
are.
When called, your program will ask for the name of a file. The input is the name
of a text file. Your program will print out the huffman codes for the text file.
For example:
To make this easier, you may make the following assumptions:
You will always receive a valid filename as input.
The file will be a text file.
Only ASCII characters between will appear in the file if anything
outside that range appears ignore it
Huffman Codes can be stored as strings, you don't need to store them in
binary. You can just store character because you are just printing the
codes.
All Huffman Codes will be shorter than characters Zeros and Ones
Display the ASCII code in the output, not the character itself to avoid
special cases for nonprinting symbols
Insert it into the heap
End For
While Heap Size is not one do
node First Minimum of Heap
node Next Minimim of Heap
Create a new tree with node on left and node on right
Insert new tree into heap
End While
The Huffman Tree is the item left in the Heap
Print out the Huffman Codes
End Function
Readme
Once your code works, you will look at how well it compresses files. The three
test files you are given are short and easy to work with. You are provided with
three additional files.
txt contains Bram Stoker's Dracula
txt contains Jonathan Swift's A Modest Proposal
pgtxt contains William Shakespeare's Hamlet
We can estimate the size of a file by assuming each character is bits. This
ignores any metadata or other data the filesystem needs. It is close enough for
this assignment. We just multiply the number of characters by
They have the following uncompressed sizes approximately:
Determine how big these three files would be if they were compressed using the
huffman encoding your program creates. You do not have to compress them, just
calculate their approximate size. Multiply how many bits each character would
take by number of times it appears. Add up all the characters for an estimate.
Put your answer in
readme.md
Extended Examples
Test
Enter File Name to read:
examplesetxt
ASCII Percent Code
Test
Enter File Name to read:
examplesetxt
ASCII Percent Code
Test
Enter File Name to read:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started