Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9216246

Have any Question?


Related Questions in Computer Engineering

Simulate a dispatcher using a priority queue system in cnew

Simulate a dispatcher using a priority queue system in C. New processes are to be entered using a GUI with priority included (numbering should be automatic). Processes are also to be terminated by GUI command. Context sw ...

Why are we in the golden age of technology entrepreneurship

Why are we in the 'golden age' of technology entrepreneurship? What factors are helping entrepreneurs more rapidly achieve their vision, and with a lower cost?

You are requested to design an information technology

You are requested to design an Information Technology Infrastructure for an international nonprofit organization. The organization has six offices, one each in Ohio, Kentucky, Toronto, Michigan, Chicago, and Indiana. Col ...

Question what is the relation between virtual memory a

Question : What is the relation between virtual memory, a memory map, physical memory and swapping to secondary memory? The response must be typed, single spaced, must be in times new roman font (size 12) and must follow ...

String loop method write a java program to meet the

((String + Loop + method) Write a Java program to meet the following requirements: 1. Prompt the user to enter three strings by using nextline(). Space can be part of the string. 2. Write a method with an input variable ...

Suppose that you have a singly-linked list l containing the

Suppose that you have a singly-linked list L containing the sequence of numbers (1,2,3,4,5,6,7,8,9). Suppose further that you have an initially empty stack S. i) Give a pseudo-code description of a method that uses only ...

Suppose that you need to create two-table database to

Suppose that you need to create two-table database to record information for a DVD rental kiosk. The following information needs to be recorded. For all movies: Movie number, title, category, rental rate, and whether or ...

Question in a sliding window protocol assume that the

Question : In a Sliding Window Protocol, assume that the senders and receivers window sizes are 3 packets each and a total of 6 packets are sent numbered 1-6. Draw time line diagrams corresponding to each of the followin ...

How do you find the minimum sample size when population

How do you find the minimum sample size when population standard deviation is anywhere between 14 to 24, and the half-width B desired could be anywhere between 2 to 7?

Youre trying to save to buy a new 190000 bmw 3 series

You're trying to save to buy a new $190,000 BMW 3 series sedan. You have $40,000 today that can be invested t your bank. The bank pays 4.8% annual interest on its accounts.  How long will it be before you have enough to ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As