c++ - Does a Huffman Binary Tree have to be proper? -
all examples find huffman coding have had number of chars work with. if odd number of chars can last internal node added tree have single child ? or have add null node of sort internal nodes have 2 children ?
if later, seems confusing because not sure how have null value char (because values being used valid ascii codes).
an odd number of char
s no problem. wouldn't lead internal node 1 child.
/\ / \ × / \ b c
the way tree constructed ensures internal nodes have 2 children, regardless of how many char
s there are.
one starts list of leaves, , in each step, (the) 2 trees lowest frequency joined making them left resp. right subtree of new - internal - node, until there 1 tree left. each internal node in final result arises joining 2 subtrees, hence has 2 children.
Comments
Post a Comment