A ternary code for an alphabet is a wayof writing each of its symbols as a distinct ternary string (i.e as  a sequence of 0's, 1's and 2's). Design a greedy algorithm that, given an alphabet and symbol frequencies as input, outputs a prefix-free ternary code with the minimum-possible average encoding length. Pls share a sample with symbols and frequencies and prove that algorithm works. Important Note to the solution: Instead of grouping together the two with lowest frequency into pairs that have the smallest total frequency, we will group together the three with lowest frequency in order to have a final result that is a ternary tree. The analysis of optimality is almost identical to the binary case. We are placing the symbols of lowest frequency lower down in the final tree and so they will have longer codewords than the more frequently occurring symbols.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

A ternary code for an alphabet is a wayof writing each of its symbols as a distinct ternary string (i.e as  a sequence of 0's, 1's and 2's). Design a greedy algorithm that, given an alphabet and symbol frequencies as input, outputs a prefix-free ternary code with the minimum-possible average encoding length. Pls share a sample with symbols and frequencies and prove that algorithm works.

Important Note to the solution:

Instead of grouping together the two with lowest frequency into pairs that have the smallest total frequency, we will group together the three with lowest frequency in order to have a final result that is a ternary tree. The analysis of optimality is almost identical to the binary case. We are placing the symbols of lowest frequency lower down in the final tree and so they will have longer codewords than the more frequently occurring symbols.

Expert Solution
Step 1: Greedy Ternary Huffman Coding Algorithm:

The problem you've described is similar to Huffman coding, a well-known algorithm for constructing variable-length prefix-free codes. In this case, we'll adapt Huffman coding to create a ternary tree, where symbols are encoded with ternary strings (sequences of 0's, 1's, and 2's). The goal is to minimize the average encoding length. The algorithm is as follows:

Greedy Ternary Huffman Coding Algorithm:

  1. Start with a list of nodes, each representing a symbol and its frequency from the input alphabet and frequencies.

  2. While there are more than three nodes in the list, do the following: a. Select the three nodes with the lowest frequencies. b. Merge these three nodes into a new node, creating a ternary tree. c. Set the frequency of the new node to be the sum of the frequencies of the merged nodes. d. Add the new node back to the list.

  3. The remaining node in the list is the root of the ternary tree.

  4. Traverse the tree to assign ternary codes to symbols:,a. Select the three nodes with the lowest frequencies. b. Merge these three nodes into a new node, creating a ternary tree. c. Set the frequency of the new node to be the sum of the frequencies of the merged nodes. d. Add the new node back to the list.

  5. The remaining node in the list is the root of the ternary tree.

  6. Traverse the tree to assign ternary codes to symbols: a. Starting at the root, traverse the tree to each leaf node. b. For each left branch taken, append '0' to the code, for each middle branch append '1', and for each right branch append '2'.

  7. The ternary codes for each symbol are the paths from the root to the respective leaf nodes.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Problems on numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education