Ternary prefix code (source code)

= Ternary prefix code
{title2=$c:\mathcal X\to\{0,1,2\}^*$}

A <prefix code> whose <codewords> use a three-symbol <alphabet>, conventionally $\{0,1,2\}$. No complete <codeword> is a prefix of another, permitting sequential decoding by following a <code tree> to a <tree leaf>. Its <expected codeword length> is $\sum_i p_i|c(i)|$ <trits> per source symbol. For source <probabilities> $(1/2,1/4,1/8,1/8)$, the <codewords> $(0,1,20,21)$ give <expected codeword length> $5/4$ <trits>.