from TreeNode import * # takes as input name of text file, fname, and returns # a list of pairs (c,n), where c is a character in the file # and n is the number of times c appears in the file def freq(fname): pass # takes a list of character frequencies (c,n) sorted in increasing order # of frequency and returns a list of initial tree objects def construct_initial_trees(sorted_frequencies): pass # takes as input two Huffman trees and returns a single tree # with a root and the two trees as sub-trees def combine(t1,t2): pass # takes as input a new tree t and a list of sorted trees and # returns a sorted list of trees after inserting t into tlist. def insertHT(t,tlist): pass # takes as input a list of sorted trees, tlist, and returns a Huffman tree # generated from tlist def construct_huffman_tree(tlist): pass # takes as input a character c and the Huffman tree, htree, and # returns the Huffman code for c based on htree def code(c,htree): pass # takes as input a plain text string s, and the Huffman tree, htree, # and returns the Huffman code for s def huffman_encoding(s,htree): pass # takes as input a string s and the Huffman tree, htree, and # returns the plain text for s based on htree def huffman_decoding(s,htree): pass def pretty_print(htree,indent): if htree != None: spaces = "" for x in range(indent): spaces = " "+spaces print(spaces,htree._symbols,htree._weight) pretty_print(htree._left,indent+2) pretty_print(htree._right,indent+2)