How do I properly build the huffman binary tree for probabilities?

95 Views Asked by At

As seen in the picture below, I have a list of probabilities and I have to order them from lowest to highest in order to compute the tree, but I am not sure the tree that I have built is correct. As far as I know, if I compute the first two values ($p_1$ and $p_4$) and if their value is higher than $p_7$, then I have to build another subtree of $p_7+p_6$ and so on ? Or maybe I am getting this wrong. Could somebody point me to the right direction on how to build this type of tree correctly with all the rules ?

enter image description here

1

There are 1 best solutions below

3
On BEST ANSWER

After combining two of the lowest probabilities (it seems you chose $x_1$ and $x_4$ for this), you should regard their combined probability ($1/8$) as a new element of your set, replacing the two that you combined. So, after you combine $x_6$ with $x_7$, the next step should not combine $x_8$ with $x_2$ but rather combine $x_8$ with the new element (because the probability of the new element, $1/8$, is less than the probability of $x_2$, $3/16$).