Question: Using Python. Using the pseudocode and basic skeleton code below, implement Huffman code with a priority queue using the helper function HuffmanCode class. No need

Using Python.

Using the pseudocode and basic skeleton code below, implement Huffman code with a priority queue using the helper function HuffmanCode 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.

#####################################################################

import heapq

class Internal_Node: def __init__(self, count, children, left=None, right=None): self.count = count self.children = children self.left = left self.right = right def __lt__(self, other): return self.count < other.count

def __eq__(self, other): return self.count == other.count

class HuffmanCode: def __init__(self, F): self.T = None self.T = dict()

######CODE HERE########## # ####Construct the Huffman Code and set C and T#################

#####################################################################

HuffmanCode(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.

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!