Knowee
Questions
Features
Study Tools

Consider the following string saved into a string type variable. We want to send it over the network to another computer. Use the given string and answer (solve) the questions given below. String: “Data Structures is one of the core courses of BS(CS) program.” Note: Double quotes are not the part of string. a. Build frequency table and Huffman encoding tree. [14 Marks] Use the following sample frequency table: Character Frequency Number of Bits used without any encoding Huffman code of each character Number of Bits used with Huffman encoding b. Calculate how many bits will be used for the above string: [6 Marks]  Without using any encoding technique  With Huffman encoding technique  What percentage of bits is saved by Huffman encoding scheme? in C++ language

Question

Consider the following string saved into a string type variable. We want to send it over the network to another computer. Use the given string and answer (solve) the questions given below.

String: “Data Structures is one of the core courses of BS(CS) program.”

Note: Double quotes are not the part of string.

a. Build frequency table and Huffman encoding tree. [14 Marks]

Use the following sample frequency table:

Character Frequency Number of Bits used without any encoding Huffman code of each character Number of Bits used with Huffman encoding

b. Calculate how many bits will be used for the above string: [6 Marks]  Without using any encoding technique  With Huffman encoding technique  What percentage of bits is saved by Huffman encoding scheme? in C++ language

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

a. Building frequency table and Huffman encoding tree:

First, we need to count the frequency of each character in the string. For simplicity, let's consider only a few characters from the string "Data Structures".

Character: D, a, t, , S, t, r, u, c, t, u, r, e, s Frequency: 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 1

Without any encoding, each character is typically represented using 8 bits.

To build the Huffman encoding tree, we start by creating a node for each character and its frequency. We then combine the two nodes with the lowest frequency to create a new node with a frequency that is the sum of the two. We repeat this process until there is only one node left, which is the root of the Huffman tree.

The Huffman code for each character is the path from the root to the character in the tree, where going to the left child adds a 0 and going to the right child adds a 1.

For example, if we have the following Huffman tree:

    (14)
   /    \
(7)      (7)

/ \ /
(3) (4) (3) (4) / \ / \ / \ /
D a t S r u c e

The Huffman code for 'D' would be '00', for 'a' would be '01', for 't' would be '10', and so on.

b. Calculating the number of bits used:

Without using any encoding technique, each character uses 8 bits, so the total number of bits used would be 8 * length of the string.

With Huffman encoding, the number of bits used for each character depends on its frequency. For example, in the above tree, 'D' uses 2 bits, 'a' uses 2 bits, 't' uses 2 bits, and so on.

The percentage of bits saved by Huffman encoding can be calculated as (1 - (total bits with Huffman / total bits without Huffman)) * 100%.

In C++ language, you can use a priority queue to build the Huffman tree and a map to store the Huffman codes for each character. The calculation of the total bits used and the percentage saved would involve iterating over the string and the map.

This problem has been solved

Similar Questions

Consider the following sentence (you don’t need to consider the spaces betweencharacters).“MADAM I AM ADAM”1. Assume that 8-bit extended ASCII encoding is used to represent the above sentence.Find out how many bytes are required to represent the above sentence.2. What is the minimum/optimum number of bits needed to represent the abovesentence?3. Calculate the number of bits that are necessary to represent the above sentence usingHuffman encoding.4. Using Huffman encoding how would you represent the following sequence ofcharacters? “DAMMA”

A text is made up of the characters a, b, c, d, e each occurring with the probability 0.11, 0.40, 0.16, 0.09 and 0.24, respectively. The optimal Huffman coding technique will have the average length of:a.2.15b.2.26c.2.40d.2.16

The following Message "B C C A B B D D A E C C B B A E D D C C", is given. Use Huffman algorithm to find the total size of the message

he following Message "B C C A B B D D A E C C B B A E D D C C", is given. Use Huffman algorithm to find the total size of the message 1 point43 bits45 bits40 bits41 bits

What is the average number of bits for each letter of the word "amazing" using Huffman coding algorithm? Select one:a.18/7b.19/7c.3d.20/7e.None of thesef.17/7

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.