Huffman Tree Algorithm
form a node for each symbol ai with weight pi;
insert the nodes in a min priority queue ordered by probability;
while the priority queue has more than one element do
n.weight := min1.weight + min2.weight;
return the last node in the priority queue.