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
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