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

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -