A Prefix-Free Code Can Mark Its Own Symbol End

In a prefix-free code, no codeword is the start of a different codeword. That lets a decoder identify a symbol as soon as its full codeword is read.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace three symbols
  2. Check a trailing fragment
  3. Stop decoding a symbol at a complete leaf
  4. Test a stream ending partway through a word

Trace three symbols

With A=0, B=10, and C=11, stream 01011 is decoded as A, B, C. The read point after 0 cannot also be inside a longer word. See prefix tests.

Check a trailing fragment

A trailing 1 can start a codeword but is incomplete by itself. The decoder should handle exhaustion at that state. End-of-file detection provides the analogous stream outcome.[1][2]

Stop decoding a symbol at a complete leaf

Take A assigned zero, B assigned ten and C assigned eleven. Reading stream 011010, the leading zero gives A. Next comes eleven for C, then zero for A and ten for B. Because no codeword is a prefix of another, recognizing a full word ends the current symbol. See prefix decoding trees.

Bits 0 11 0 10
Symbols A C A B
Each completed bit prefix returns the decoder to the root

Test a stream ending partway through a word

A final one alone does not select B or C and needs an incomplete-stream outcome. Prefix-free structure supports unambiguous symbol boundaries but an outer message may still need a length.

References

  1. Claude E. Shannon, A Mathematical Theory of Communication ↩
  2. David J. C. MacKay, Information Theory, Inference, and Learning Algorithms ↩