Shannon-Fano coding comprises two related prefix code constructions. Shannon coding assigns lengths to symbols of probability ; Fano coding recursively partitions the ordered symbols into groups of nearly equal total probability and assigns a bit at each partition.
Recursively split an ordered list of positive source probabilities into contiguous blocks, choosing each cut to minimize the difference between the total masses of the two children. The resulting binary prefix code has expected codeword length less than , where is its source Shannon entropy. If the probabilities were in nonincreasing order, its expected length is less than .
To prove this, an interior node of mass with child masses contributes to the expected path length and to the Shannon entropy, by the chain rule for information entropy. The inequality bounds that node's redundancy by . If the cut is between probabilities , shifting the cut by one position cannot improve the imbalance. On the heavier side this gives or , respectively; a singleton heavier side gives the same inequality directly. Thus .
Articles by others on the same topic
Shannon–Fano coding is a method of lossless data compression that assigns variable-length codes to input characters based on their probabilities of occurrence. It is a precursor to more advanced coding techniques like Huffman coding. The fundamental steps involved in Shannon–Fano coding are as follows: 1. **Character Frequency Calculation**: Determine the frequency or probability of each character that needs to be encoded. 2. **Sorting**: List the characters in decreasing order of their probabilities or frequencies.