A binary prefix code assigns distinct finite binary strings to the source symbols, with no assigned string a prefix of another. It is instantaneous because a complete codeword is recognized without needing the next word's bits.
Associate a word of length with its dyadic subinterval of of length . A prefix relation corresponds to interval containment. Prefix-free words therefore give disjoint intervals, whose total length is at most one. This proves necessity of Kraft inequality.
For sufficiency, sort the requested nonnegative integer lengths increasingly and construct a code greedily in a binary tree. At depth , the preceding codewords forbid exactly nodes. The assumed inequality, retaining the positive contribution of the present word, bounds this integer by . Thus at least one node is available; choose it. It is not below an earlier codeword, and the nondecreasing lengths prevent it from being a proper ancestor of an earlier word. Continue to obtain a prefix code of all the required lengths. Hence
Work on the source support, so its listed probabilities are positive; zero-probability symbols may be omitted. An optimal binary prefix code minimizes the expected codeword length for that distribution. The same optimal expected length is attained when optimization is over uniquely decipherable codes, by the converse and existence parts of Kraft–McMillan inequality.
Choose Shannon lengths . They satisfy , so the preceding existence theorem gives a prefix code with those lengths. Also for every symbol, including the integer cases. Thus its expected length is less than . An optimal code cannot have a larger expected length, proving
For a deterministic one-symbol source the empty word has length zero, consistent with this bound.
At an interior tree node write for the total masses in its two children, and . Counting path lengths and telescoping the Shannon entropy over the binary decisions gives
Indeed each symbol contributes its probability once per ancestral interior node to the first sum. In the second sum, expanding cancels the interior terms and leaves the source Shannon entropy. The supplied inequality now bounds redundancy by
Consider the cut between adjacent symbols made at one node. If its left side is heavier, moving its last symbol to the right must not improve the chosen cut. Writing , this says , which implies ; when the left side is a singleton the same bound is immediate. If the right side is heavier, the corresponding argument gives . In all cases
Recursive subdivision of contiguous blocks uses each original gap exactly once. Summing over the gaps therefore gives
proving . If probabilities are already nonincreasing, each maximum is and the improved bound is . Thus the sorted version has expected length less than , although it need not be optimal. For one symbol the assertions hold directly. This is the Fano slice code redundancy bound.

Articles by others on the same topic (0)

There are currently no matching articles.