next up previous
Next: Up: Previous:

Prefix Codes

Note: An optimal code is always represented by a full binary tree in which every non-leaf node has exactly two children.



Given tree T, compute the number of bits to represent file.
Let C = set of unique characters in file.
Let f(c) = frequency of character c in file.
Let
dT(c) = depth of c's leaf node in T



Then, the number of bits required to encode a file B(T) = \(\sum_{c \in C} f(c) d_T(c)\).

B(T) = cost of tree T


next up previous
Next: Up: Previous: