chap binary trees letter frequency figure the relative frequencies for eight selected letters the weighted path length of leaf to be its weight times its depth the binary tree with minimum external path weight is the one with the minimum sum of weighted path lengths for the given set of leaves letter with high weight should have low depthso that it will count the least against the total path length as resultanother letter might be pushed deeper in the tree if it has less weight the process of building the huffman tree for letters is quite simple firstcreate collection of initial huffman treeseach of which is single leaf node containing one of the letters put the partial trees onto min-heap ( priority queueorganized by weight (frequencynextremove the first two trees (the ones with lowest weightfrom the heap join these two trees together to create new tree whose root has the two trees as childrenand whose weight is the sum of the weights of the two trees put this new tree back on the heap this process is repeated until all of the partial huffman trees have been combined into one example figure illustrates part of the huffman tree construction process for the eight letters of figure ranking and arbitrarily by alphabetical orderthe letters are ordered by frequency as letter frequency because the first two letters on the list are and kthey are selected to be the first trees joined together they become the children of root node with weight thusa tree whose root has weight is placed back on the listwhere it takes up the first position the next step is to take values and off the heap (corresponding to the partial tree with two leaf nodes built in the last stepand the partial tree storing the letter mrespectivelyand join them together the resulting root node has weight and so this tree is placed back into the heap its priority will be between the trees with values (for letter cand (for letter uthis process continues until tree whose root has weight is built this tree is shown in figure figure shows an implementation for huffman tree nodes this implementation is similar to the varbinnode implementation of figure there is an abstract base classnamed huffnodeand two subclassesnamed leafnode