Build Huffman Tree with Ternary System

  • Context: MHB 
  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Algorithm
Click For Summary
SUMMARY

The discussion focuses on constructing a Huffman Tree using a ternary system, where each node can have up to three children instead of two. The process involves creating leaf nodes for unique characters, building a min heap, and repeatedly extracting the three nodes with the lowest frequencies to form new internal nodes. This method ensures that the resulting tree is optimal for encoding characters with ternary codes. The participants also inquire about proving the optimality of the algorithm for ternary codes.

PREREQUISITES
  • Understanding of Huffman coding principles
  • Familiarity with min heap data structures
  • Knowledge of tree data structures
  • Basic concepts of algorithm optimization
NEXT STEPS
  • Research the mathematical proof for optimality in Huffman coding
  • Explore ternary tree implementations in programming languages
  • Learn about priority queues and their applications in algorithms
  • Investigate variations of Huffman coding for different numeral systems
USEFUL FOR

Computer scientists, software engineers, and algorithm enthusiasts interested in data compression techniques and tree data structures.

evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hello! (Wave)

Steps to build Huffman Tree
Input is array of unique characters along with their frequency of occurrences and output is Huffman Tree.


  • 1. Create a leaf node for each unique character and build a min heap of all leaf nodes (Min Heap is used as a priority queue. The value of frequency field is used to compare two nodes in min heap. Initially, the least frequent character is at root)

    2. Extract two nodes with the minimum frequency from the min heap.

    3. Create a new internal node with frequency equal to the sum of the two nodes frequencies. Make the first extracted node as its left child and the other extracted node as its right child. Add this node to the min heap.

    4. Repeat steps#2 and #3 until the heap contains only one node. The remaining node is the root node and the tree is complete.
At a heap, a node can have at most $2$ children, right?So if we would like to generalize the Huffman algorithm for coded words in ternary system (i.e. coded words using the symbols $0$ , $1$ and $2$ ) what could we do? Do we have to create a tree all the nodes of which have $3$ children? (Thinking)
 
Technology news on Phys.org
I think that it would be as follows.

Steps to build Huffman Tree
Input is array of unique characters along with their frequency of occurrences and output is Huffman Tree.


  • 1. Create a leaf node for each unique character and build a min heap of all leaf nodes

    2. Extract three nodes with the minimum frequency from the min heap.

    3. Create a new internal node with frequency equal to the sum of the three nodes frequencies. Make the first extracted node as its left child, the second extracted node as its middle child and the third extracted node as its right child. Add this node to the min heap.

    4. Repeat steps#2 and #3 until the heap contains only one node. The remaining node is the root node and the tree is complete.
How can we prove that the algorithm yields optimal ternary codes? (Thinking)
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
4
Views
1K
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
1
Views
2K