Reading a Prefix Code as a Tree
A binary prefix tree can label edges with bits and leaves with symbols. Decoding follows edges from the root until it reaches a leaf.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace 1010
With leaves A at 0, B at 10, and C at 11, bits 1010 traverse the B path twice, restarting at the root after each leaf. These codeword boundaries follow the path structure.
Check unfinished paths
If bits end on an internal node, the last symbol is incomplete under this code. A tree traversal can also enumerate all codewords by recording root-to-leaf paths.[1][2]
Trace branches one input bit at a time
A decoding tree has A as the zero child of the root. The one child is an internal node with B at zero and C at one. Reading one then zero reaches B before restarting at the root. See tree traversal basics.
Root --1→ inner --0→ B, emit B
Root --0→ A, emit A
Stream 100 decodes to BA
Mark unfinished and impossible branches separately
A truncated stream can end at an internal node. A non-full tree may also lack an outgoing edge for an invalid sequence. Test both conditions independently where the code has them.