Question
Java help with following method: public HuffTree buildHuffmanTree() { // Build forest of HuffTrees from huffMap // Create the heap // add code // Retrieve
Java help with following method:
public HuffTree buildHuffmanTree() { // Build forest of HuffTrees from huffMap // Create the heap // add code
// Retrieve the set of keys // add code
// Loop through the set of keys (use for each loop): // Use the key to get the HuffElement // Create a HuffTree with a single node from the HuffElement // Add the HuffTree to the Heap // add code
// Loop through Heap, removing two lowest count tree // Create a new HuffTree using these two trees // Add new tree to the Heap
// add code
// Return the final tree: Last tree in heap // add code }
........................................
Build the Huffman tree as follows:
Create a leaf node for each unique character and build the minimum heap of all leaf nodes, stored with the character and the frequency.
Remove the two heap node elements with the minimum frequency from the minimum heap.
Create a new internal node with frequency equal to the sum of the two nodes frequencies. Make the first removed node as its left child and the other removed node as its right child. Add this node to the minimum heap.
Repeat steps b and c until the heap contains only one node element. The remaining node is the root node and the tree is complete.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started