Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please provide full Java source code for the task along with step-by-step explanation. Using Java Data Compression Write a program to decipher messages encoded using

image text in transcribedimage text in transcribed

Please provide full Java source code for the task along with step-by-step explanation.

Using Java Data Compression Write a program to decipher messages encoded using a prefix code, given the encoding tree. Such codes are widely used in applications that compress data, including JPEG for images, MP3 for music, and DivX for video. Prefix codes. A prefix code is most easily represented by a binary tree in which the external nodes are labeled with single characters that are combined to form the message. The encoding for a character is determined by following the path down from the root of the tree to the external node that holds that character: a 0 bit identifies a left branch in the path, and a 1 bit identifies a right branch. In the following tree, black circles are internal nodes and gray squares are external nodes. The code for is , because the external node holding is reached from the root by taking 3 consecutive right branches. The other codes are given in the table below. Note that each character can be encoded with a different number of bits. In the example above, the character ' a ' is encoded with a single bit, while the character ' d ' is encoded with 4 bits. This is a fundamental property of prefix codes. In order for this encoding scheme to reduce the number of bits in a message, we use short encodings for frequently used characters, and long encodings for infrequent ones. A second fundamental property of prefix codes is that messages can be formed by simply stringing together the code bits from left to right. For example, the bitstring encodes the message ' '. The first 0 must encode then the next three 1 's must encode then must encode and so on as follows: The codes can be run together because no encoding is a prefix of another one. This property defines a prefix code, and it allows us to represent the character encodings with a binary tree, as shown above. To decode a given bit string: - Start at the root of the tree. - Repeat until you reach an external leaf node. - Read one message bit. - Take the left branch in the tree if the bit is 0 ; take the right branch if it is 1 . - Print the character in that external node. This whole process is repeated, starting over at the root, until all of the bits in the compressed message are exhausted. Your main task is to parse the binary tree and implement this procedure. Representing the binary tree. To decode a bit string, you need the binary tree that stores the character encodings. We use the preorder traversal of the binary tree to represent the tree itself. Internal nodes are labeled with the special character ' '. (For convenience, we artificially restrict ourselves to messages that do not contain this special character.) The preorder traversal of the above tree is: Input format. The input will consist of the preorder traversal of the binary tree, followed immediately on a new line by the compressed message. For the example above, the input file is In order to read the input one character at a time, use the library CharStdIn.java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions