The template contains an array of letter/frequency pairs to be used as input to the Huffman minimum redundancy code algorithm discussed in class. The template also contains a full min-heap...


The template contains an array of letter/frequency pairs to be used as input to the Huffman minimum redundancy code algorithm discussed in class. The template also contains a full min-heap implementation that you can use for the priority queue needed by the Huffman algorithm.


Follow the comments in the execute() method to build out five functions that implement the algorithm and display the result. An estimated line length for each function is given in comments. The HNode contains all the member variables and accessors needed for both the Huffman and Binary Tree algorithms (plus others that may not be needed). You will also need to fill out the two binary tree methods btInsert() and btFind(). The functions are:



  1. build the min-priority queue by frequency, and a binary tree keyed by letter to track the letter nodes (the HNode is keyed by the frequency, so this just involves insert() to the heap and btInsert() to the tree)

  2. build the Huffman tree from the priority queue and frequencies, also using HNodes for pseudo-elements

  3. make the Huffman codes for each letter by processing the binary tree in pre-order (the letters can actually be processed in any order, pre-order is just convenient)

  4. display the Huffman codes by processing the binary tree in in-order (this displays them in alphabetical order)

  5. encode and display the given phrase using the Huffman codes (this uses btFind()). The format is given in the comments and displayed below.


Your program output should look like this:


letter code:1101
letter a code:010
letter c code:0011
letter e code:101
letter i code:011
letter n code:1111
letter p code:11001
letter r code:000
letter s code:100
letter t code:1110
letter u code:0010
letter v code:110000
letter y code:110001
p:11001 a:010 c:0011 e:101 :1101 u:0010 n:1111 i:011 v:110000 e:101 r:000 s:100 i:011 t:1110 y:110001

Jun 22, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here