Use huffman coding for compression-decompression.

Assignment Help Basic Computer Science
Reference no: EM1340880

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: EM1340880

Questions Cloud

Show the execution stage of project management : Describe the 95 percent phenomenon that sometimes materializes as a project nears closing
Healthcare planning and marketing : Course Name: BUS 5658 Healthcare Planning and Marketing, Discusses and applies the concepts of healthcare planning and marketing to healthcare delivery, assessment of community needs, and resource planning in both ambulatory and clinical settings.
Show the understanding and managing conflit : Describe the differences between interpersonal, intrapersonal, intergroup, and intragroup conflicts and How might supervisors diagnose these types of conflict among their subordinate
Explain the organizational structures : Describe what types of control processes might be found in each of the 5. organizational structures and Explain what types of quality management processes might be found in each of the organizational structures
Use huffman coding for compression-decompression. : Use Huffman coding for compression/decompression. 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.
Explain managing groups and teams in gaming : Explain How can coevolutionary gaming facilitate group decision-making and What are its limitations
Suggested skills for project managers : Suggested Skills for Project Managers - What are suggested skills for all project managers
Explain techniques to resolve conflict : Show the following techniques that help resolve conflicts among people or teams: vision, bargaining-negotiation, mediation, and facilitating communication
Purpose of a staffing management plan : Staffing Management Plan - Explain What is the purpose of a staffing management plan and What factors must be considered when creating one

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Explain the term omniscience

Explain the term omniscience Explain the importance of autonomy in an agent Develop the task environment for an interactive language tutor

  Prepare business income statement for the period

With growing importance of computerised accounting systems, which inventory system (perpetual or periodic) has become more popular?  Explain why

  What your research aims to do

You need to describe what your research aims to do, the objectives that need to be meet to get to the final aim, the context and technical background of the work and also why it is important that this work is carried out.

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  Descriptions of data formats and to interpret raw data

The aim of this project is to exercise and test your ability to read and understand descriptions of data formats and to interpret raw data according to a particular format.  In this exercise you will produce and read the dump of a ZIP file.

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Application development and programming languages

Compare and contrast object-oriented languages (Java, C++, C#, etc.) to imperative languages (C, Pascal, etc.) in terms of: Programmability, Maintainability, Performance, Development tools

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Cores on computer systems

Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency,

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

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