A source code assigns to each (possible) source sequence
a
binary codeword
with length
.
We want the lengths of the codewords to be as short as possible,
however it is required that the source sequence can be reconstructed
from its codeword.
Here we only consider prefix codes.
In a prefix code no codeword is the prefix of any other codeword.
Therefore a prefix code is instantaneously uniquely decodable,
i.e. when we receive the last digit of a codeword we know that it is
the last one.
Example:Consider for source sequences of length T=2 the assignment in the table below.
The lengths of the codewords of a binary prefix code satisfy Kraft's inequality (see e.g. Cover and Thomas[1], page 82):
Proof:Let
. A codeword
has
descendants at level
. In a prefix code no two
different codewords can have an identical descendant at level
.
Therefore
.
Example:For the code
we obtain the Kraft sum
.