Huffman coding for compression

Assignment Help Computer Engineering
Reference no: EM13306531

Description

In the last episode of the Mafghanistan trilogy, the Mamerican forces invaded liberated Mafghanistan in pursuit of mineral freedom. However, terrorist attacks spread across Mafghanistan like the oil spill from the Deepwater Horizon. You, as the Commanding General of the Mamerican forces and their Mafghan puppets allies, just discovered the book, which describes efficient algorithms for terminating insurgents, that would ensure victory in Mafghanistan. You wish to send this book to all the troops via the Internet ASAP. However, due to the astronomical deficit of the Mamerican government, you wish to compress the book to reduce your ISP charges.

Use Huffman coding for compression/decompression.

The input to compression is a sequence of 8-bit characters.

When computing the Huffman tree, do not compute the code for any character that does not exist in the input. Do not insert these characters into the min-heap.

To ensure consistent behavior between your program and mine, during the delete operation on the min-heap, you need to determine the priority of the subtrees that have the same weight. Let S and T be two subtrees. S has a higher priority than T if and only if:

S's weight is smaller than T's weight, or

S and T have the same weight, and the smallest character (in ASCII value) in any of S's leaf nodes is smaller than that in any of T's leaf nodes.

Under this definition, the delete operation should remove the subtree with the highest priority from the min-heap. Also when merging two subtrees, set the tree with the lower priority as the left subtree (whose code is 0), and the tree with the higher priority as the right subtree (whose code is 1).

You may NOT use STL classes except the string class.

Command line: Your program accepts an optional command line argument "-d":

When this argument is absent, compress the input and writes the compressed data to the output.

When this argument is present, decompress the input and writes the decompressed data to the output.

Read input from cin and write output to cout.

Uncompressed data: The uncompressed data contains a sequence of 8-bit characters. The input contains at most 232-1 characters.

Compressed data: The compressed data contains three sections:

Magic cookie. This section contains 8 characters: the string "HUFFMA5" followed by the ASCII 0 character ('\0').

Frequencies. This section contains the frequencies of all the characters from ASCII 0 to ASCII 255, even if a characer is absent from the uncompressed data. The frequency of a character is its count in the uncompressed data. Order the frequencies by the ASCII values of their corresponding characters. Write each frequency as a 4-byte unsigned integer in the little-endian form.

Compressed data. This section contains the codes of all the characters in the same order as they appear in the uncompressed data. Since this section contains a sequence of bits but the smallest unit of data is a byte in files, you need to convert bits into bytes by the following rules:

Starting from the beginning of the bit sequence, convert each sequence of 8 consecutive bits into 1 byte. If the number of bits is not a multiple of 8, pad the end of the bit sequence with 0s.

When converting 8 bits into 1 byte, let the first bit be the least significant bit (LSB) in the byte, the second bit be the second LSB, and so on.

We will test the decompression function of your program with only valid compressed data, so your program need not handle errors in the compressed data.

Reference no: EM13306531

Questions Cloud

Describe the graphical coordinate system in java : How do you specify that the color orange will be used as fill when using the Graphics class? Give the Java statement needed.
Obtain the index of refraction of the glass : Light is reflected from a glass coffee table. When the angle of incidence is 50.0 °, What is the index of refraction of the glass
Case study on vanust - a tale of two perspectives : Case study on Vanust - a tale of two perspectives
Will everything eventually be ethernet / csma/cd : Is Ethernet that good that it's the predominant form of LAN? Will everything eventually be Ethernet / CSMA/CD?
Huffman coding for compression : Huffman coding for compression - Starting from the beginning of the bit sequence, convert each sequence of 8 consecutive bits into 1 byte. If the number of bits is not a multiple of 8, pad the end of the bit sequence with 0s.
Calculate distance downwind xl at which the plume released : A powerplant is burning coal on a cold, clear winter morning at 8am with a wind speed of 2.6m/s measure at 30m and an inversion layer with its base height of 697m. The effective stack height is 30m.
Calculate the maximum coefficient of performance : It is desired to build a heat pump that has an output temperature of 31 °C. Calculate the maximum coefficient of performance for the pump when the input source is ground water at 8.1 °C
Describe the difference between the two locations at time t : The peak-hour volumes at two locations were counted and found to be equal. However, the PHFs were .85 at the first location and .60 at the second. Describe the difference between the two locations if t=5 min.
How high can that person climb the ladder before the slip : A ladder is supported by a horizontal floor and a vertical wall. Is 15 feet long and weighs 50 lbs, with the weight concentrated at its midlength. The ladder supports a person weighing 180 lbs.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Handling of global ethics issue by organizations

Our textbook describes the ethics as “the principles of right and wrong which individuals utilize in order to make choices in order to guide their behaviors”.One global ethical issue is software piracy. What can the organizations such as Microsoft ..

  Write down a new program in pseudo-code

desplay what PC monitor will display when values 86, 55, and 100 are used.

  Ms access usually suggested as a good candidate

Why is a PC based DBMS like MS Access often suggested as a good candidate to use in story boarding/prototyping the user interface presentation screens and basic database functionality for the new database development (even though MS Access is not ..

  How to designing a database for implementation

As we start designing a database for implementation should we use the latest and greatest technology? Does the user need a flat-file or object-oriented database? Give an instance of each and how it would apply to the basic database designer goo ro..

  Why the lowest possible temperature is absolute zero

Accept inputs from user: a beginning temperature, an ending temperature, and an increment value (all Fahrenheit).

  Design visual basic 2010 program to analyze a mortgage

Write down a Visual Basic 2010 program to analyze a mortgage. The user should enter the amount of the loan, the annual rate of interest, and the duration of the loan in months.

  Visual logic

Consider that you are working with “Visual Logic”. Develop the logic for a program which enables a user to enter the 10 numbers, and then display them in reverse order of their entry.

  Identify the functions of a channel service unit

How are they used in the corporate environment.

  Feel free to research the internet

Did OOD/OOP meet the predictions? Feel free to research the internet.although , you should write a few sentences in your own words.

  How quick kruskal''s algorithm run

imagine that all edge weights in a graph are integers in the range from 1 to |V|.how quick Kruskal's algorithm run.

  Write down a program to solve linear system

Write down a program to solve linear system

  How it influence it department''s ability to maintain

be sure to address readability as a characteristic and how it will influence an IT department's ability to maintain custom software for a corporation.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd