A set of eight messages with probabilities of $0.2$, $0.15$, $0.15$, $0.1$, $0.1$, $0.1$, $0.1$, and $0.1$ are encoded into a ternary Huffman code.
One set of Huffman codewords are {$2, 01, 02, 10, 11, 12, 000, 001$} with the average length of the codeword(L) = $2$.
Another set of Huffman codewords are {$00, 01, 02, 10, 11, 12, 20, 21$} also with the average length of the codeword(L) = $2$.
I want to know which set of codewords is better. And if its dependent on the application, please provide some examples.
There are multiple reasons you should be interested in the fixed length coding.
$\sigma^2 = E[(x-\mu)^2] = 1 \times 0.2 + 1 \times 0.1 + 1 \times 0.1 = 0.4$