*Symbol* | *Code 1* | *Code 2* | *Code 3* |
A | 1 | 1 | 11 |
B | 2 | 22 | 12 |
C | 12 | 12 | 21 |
The average length of the Huffman codeword () is defined as:
where is the actual length of the encoding for the symbol .
(defun queue-length (queue) “Returns as two values the number of elements in the queue and the maximum number of elements the queue can hold.” (check-type queue queue) (let ((length (length (queue-elements queue))) (delta (the fixnum (- (queue-put-ptr queue) (queue-get-ptr queue))))) (declare (fixnum length delta)) ;; The maximum number of elements the queue can hold is ;; (1- LENGTH) because a queue is empty when put-ptr = ;; get-ptr. (values (mod delta length) (the fixnum (1- length)))))
If each node has a sibling (except the root), and the breadth first right to left traversal generates a list of nodes with non-increasing frequency, it can be proven that a tree adhering to the sibling property is a Huffman tree.