MHB Build Huffman Tree with Ternary System

  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Algorithm
AI Thread Summary
The discussion outlines the process of building a Huffman Tree, starting with an array of unique characters and their frequencies. The initial steps involve creating leaf nodes for each character and constructing a min heap to prioritize nodes by frequency. The algorithm extracts the two nodes with the lowest frequencies, combines them into a new internal node, and continues this process until only one node remains, which becomes the root of the tree.An extension of the Huffman algorithm for a ternary system is proposed, where nodes can have three children instead of two. The modified steps include creating a min heap, extracting three nodes with the lowest frequencies, and forming a new internal node with these nodes as left, middle, and right children. The process repeats until a single node remains.The discussion raises the question of how to prove that this modified algorithm yields optimal ternary codes, indicating a need for further exploration into the theoretical foundations of the algorithm's efficiency in this context.
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)
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top