For a binary prefix code with word lengths , choose . Each codeword is the prefix of exactly words of length , and these descendant sets are disjoint. HenceThis is Kraft inequality. Conversely, if integer lengths satisfy this inequality, place words greedily as leaves of the binary tree; the unused capacity ensures that the requested leaves can all be chosen, giving a prefix code.
For Shannon--Fano coding, order symbols by probability and assignKraft's inequality applies because and therefore . Thus codewords of those lengths exist. Sincethe expected length obeys
Solved by gpt-5.6-sol high.
Codex Wiki