Question: 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 0-127 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 0 because you are just printing the
codes.
All Huffman Codes will be shorter than 127 characters (Zeros and Ones).
Display the ASCII code in the output, not the character itself (to avoid
special cases for non-printing symbols)
Insert it into the heap
End For
While Heap Size is not one do
node01= First Minimum of Heap
node02= Next Minimim of Heap
Create a new tree with node01 on left and node02 on right
Insert new tree into heap
End While
The Huffman Tree is the 1 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.
345-0.txt contains Bram Stoker's Dracula
1080-0.txt contains Jonathan Swift's A Modest Proposal
pg2265.txt contains William Shakespeare's Hamlet
We can estimate the size of a file by assuming each character is 8 bits. This
ignores any meta-data or other data the filesystem needs. It is close enough for
this assignment. We just multiply the number of characters by 8.
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 01
Enter File Name to read:
examples/e1.txt
| ASCII | Percent | Code |
Test 02
Enter File Name to read:
examples/e2.txt
| ASCII | Percent | Code |
|------|--------|-----|
|97|0.14000|101|
|98|0.08000|001|
|99|0.13000|100|
|100|0.24000|01|
|101|0.07000|000|
|102|0.34000|11|
Test 03
Enter File Name to read:
 In this assignment, you will implement Huffman Encoding. You will not

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!