Question: In PYTHON. Using the pseudocode below, implement Huffman code using the helper function Huffman_Tree class. No need to make the encoding and decoding functions, just

In PYTHON.

Using the pseudocode below, implement Huffman code using the helper function Huffman_Tree class. No need to make the encoding and decoding functions, just need to construct Huffman code and use it to set T and C.

F is the inputed dictionary of the form produced by get frequencies. T is the root node of the Huffman code tree that would be used for decoding. C is the dictionary that would be used for encoding. The keys of C are all symbols occurring in an input string.

-Huffman_Tree(F): - Initialize n nodes v_1,...,v_n with v_i.char=c_i and v_i.frequency = F[c_i]. - Insert nodes v_1,...,v_n into the min-priority queue Q. - while Q > 1: - Allocate a new node z. - z.left = x = Q.extract_min() - z.right = y = Q.extract_min() - z.frequency = x.frequency + y.frequency - Q.insert(z) - T = Q.extract_min() - Construct C by running DFS on T. - Return T and C.

HINT: import heapq # use priority queue class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!