Optimal one-to-one binary code
ID: optimal-one-to-one-binary-code
Suppose one source message is transmitted with its endpoint supplied externally, and allow the empty word. List source symbols in decreasing order of probability, , and assign distinct binary words in increasing length order. Then the th word has length , minimizing expected codeword length among one-to-one source codes.[ref]
There are binary words of length at most . This proves the length formula. If a more probable symbol had a longer word than a less probable one, exchanging the two would decrease or preserve the expected value of the length, proving optimality.
For probabilities , use the empty word,
0 and 1. The average is bit, compared with bits for an optimal binary prefix code. The difference uses the supplied endpoint: the three-word assignment cannot decode an arbitrary concatenated message stream without framing information. New to topics? Read the docs here!