next up previous
Next: Greedy Algorithm for Huffman Up: CSE 2320: Algorithms and Previous: Prefix Codes

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.
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

Copyright © 1998 The University of Texas at Arlington