Question

4. (10 pts.) Cost of a prefix-free encoding The basic intuition behind Huffmans algorithm is that frequent symbols should ha
0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

Step 1:

Minimum total cost of prefix-free encoding:

We take a text with “m” different together symbol and its occurrences of f1 , f2, f3 and cost per bit for ith symbol is denoted as ci.

Cost of encoding :

Huffman’s algorithm:

Cost = im m i=1 =   fi . li

Here :

“fi” denotes as frequency distribution of the ith character.

“li”denotes as length of the ith character.

The cost of prefix-free encoding represented as follows:

Cost = im m i=1 = fi . li . ci

Where,

“fi. ci” denotes as frequency of the ith character.

“li” denotes as length of the ith character.

  

Step 2:

Minimum cost of prefix-free encoding:

Huffman encoding is an easy method.

• Each tree contains only one node, which corresponds to each character.

• Join the pair of tree with the small range of frequency until to get the root node.

• Then, check the tree for each symbol and traverse the tree to write the code character.

1. Here, “0” bit for left side traversal of tree.

2. “1” bit for right side traversal of tree

  • Depth of the leaf in ith word in tree di is equal to the length of the ith word “1616832958457_blob” with that leaf.
  • Then, the minimum cost of prefix-free encoding can also be represented as,

Cost = im m i=1 = fi . di

Where,

fi denotes as frequency distribution of the “ith” character.

di denotes as depth of the “ith” character.

Hence, Huffman encoding is known as the minimum cost of prefix-free encoding.

Step 3:

For example:

Construction of the Huffman encoding tree:

Inputs are,

• character A with frequency of 31%,character C with frequency of 20%, character G with frequency of 9%, and character T with frequency of 40%.

Huffman encoding is displayed under with example of a tree and frequency of the character with square brackets.

2 % 1 6o 1 T [40 A [31 29 1 G [q C[ 20

From the Huffman encoding tree,

• Get the tree for character “A” which is from root node, 01.

• Get the tree for character “C” which is from the root node , 000.

• Get the tree for character “G” which is from the root node , 001.

• Get the tree for character “T” which is from the root node , 1.

Hence, the Huffman encoding table is shown below:

Step 4:

Character

CodeWord

            A

01

            C

000

            G

001

            T

       1

The time complexity of the following encoding is : O(m*logm)

This can be optimised to : O(m)

1. Create two empty queue.

2. Then each leaf node must create a distinct character and then we need to enqueue it to first queue in increasing order of their respective frequency.

3. The nodes of with minimum frequency are dequed depending on the front of the queue.

1. If second size is 0 then deque the first queue.

2. If first queue size is 0 then deque the second queue.

3. If both the above not satisfied compare the front of the queue and take the minimum.

4. create nodes with frequency equal to sum of the nodes. Then repeat step 3 and 4 while there is more than one node in the queue. The left node is the root node.

Hence, this character is the minimum cost prefix code for this distribution.

Hope this helps! please give a thumbs up, if any queries kindly ask in the comment section.

Add a comment
Know the answer?
Add Answer to:
Cost of a prefix-free encoding The basic intuition behind Huffman's algorithm is that frequent symbols should...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Case Study 1: Should a Computer Grade Your Essays? Would you like your college essays graded...

    Case Study 1: Should a Computer Grade Your Essays? Would you like your college essays graded by a computer? Well, you just might find that happening in your next course. In April 2013, EdX, a Harvard/MIT joint venture to develop massively open online courses (MOOCs), launched an essay-scoring program. Using arti ficial intelligence technology, essays and short answers are immediately scored and feedback tendered, allowing students to revise, resubmit, and improve their grade as many times as necessary. The non-profit...

  • Actions that damage a company and its employees should be stamped out, everyone would agree. But ...

    Actions that damage a company and its employees should be stamped out, everyone would agree. But should the people responsible be stamped out, too? HBR CASE STUDY The Reign of Zero Tolerance by Ben Gerson "Mr. Pemberton?" manager. The guards had radioed her that the "Yes, that's me," Simon replied distractedly, his back turned. target wasn't putting up much resistance. "Your personal belongings will be messen The two burly gentlemen who had suddenly gered to your home later today," Sallie...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT