Definition: A variable-length coding based on the frequency of occurrence of each character. Divide the characters into two sets with the frequency of each set as close to half as possible, and assign the sets either 0 or 1 coding. Repeatedly divide the sets until each character has a unique coding.
See also arithmetic coding, Huffman coding, Zipf's law.
Note: Shannon-Fano is a minimal prefix code. Huffman is optimal for character coding (one character-one code word) and simple to program. Arithmetic coding is better still, since it can allocate fractional bits, but is more complicated and has patents.
Debra A. Lelewer's and Daniel S. Hirschberg's survey of data compression.
If you have suggestions, corrections, or comments, please get in touch with Paul Black.
Entry modified 4 January 2005.
HTML page formatted Fri Feb 23 10:06:08 2018.
Cite this as:
Paul E. Black, "Shannon-Fano coding", in Dictionary of Algorithms and Data Structures [online], Vreda Pieterse and Paul E. Black, eds. 4 January 2005. (accessed TODAY) Available from: https://www.nist.gov/dads/HTML/shannonFano.html