Difference Between Huffman Coding and Shannon Fano Coding

The primary function of a communication system is to transfer a message signal from a sender to the receiver. In the process of data transfer, the signal used to transfer the data should have the necessary properties required for the transmission as per the transmission channel. Hence, there are some information coding techniques used to transform the message signal into a transferrable signal through the transmission channel. Two of such information coding schemes are Huffman Coding and Shannon Fano Coding.

The most basic difference between Huffman Coding and Shannon Fano Coding is that the Huffman coding provides a variable length encoding, while the Shannon Fano Coding provides a limited length encoding. Read this article to find out more about Huffman Coding and Shannon Fano Coding and how they are different from each other.

What is Huffman Coding?

Huffman coding is a compression technique that handles the data compression of ASCII characters. Developed by David Huffman in 1952, the Huffman coding is the compression algorithm that is based on the top−down approach. In this algorithm, a binary tree is created in a top−down manner to produce a minimal sequence. It translates the characters contained in a data file into a binary code. The Huffman coding is a lossless text compression method because in this method, the compressed data can be restored to its original format.

Huffman coding uses a variable−length encoding scheme, where each symbol in the input data is assigned a binary code based on its frequency of occurrence. This allows for efficient compression of the data, as symbols that occur more frequently in the input will be assigned shorter codes, reducing the overall size of the encoded data.

What is Shannon Fano Coding?

Shannon Fano Coding is also an encoding algorithm used to generate a uniquely decodable code. It was developed by Claude Shannon and Robert Fano in 1949, earlier than the Huffman Coding technique. Similar to the Huffman coding, the Shannon Fano Coding also uses the probabilities of the data for encoding. However, this algorithm does not ensure the optimal code generation. The Shannon Fano coding uses cumulative distribution function.

Instead of assigning binary codes to symbols based on their frequency, it uses a hierarchical approach to divide the symbols into two groups, with each group being assigned a prefix to form the code for each symbol. This can also lead to efficient compression of the data, but the encoding process is generally slower than Huffman coding.

Difference between Huffman Coding and Shannon Fano Coding

The following table highlights all the key differences between Huffman Coding and Shannon Fano Coding −

S. No. Huffman Coding Shannon Fano Coding
1. It was invented in the year 1952. It was invented in the year 1949.
2 It has good efficiency. It has moderate efficiency.
3. It was developed by David Huffman. It was developed by Claude Shannon and Robert Fano.
4. It provides high optimization. It provides low optimization.
5. It is based on the source symbol probabilities. It is based on the cumulative distribution function.


The most significant difference between the two encoding algorithms is that the Huffman Coding is more efficient and optimal as compared to the Shannon Fano Coding. Both the coding systems use lossless data compression algorithms and both are used in various applications, including image and video compression, audio compression, and data transmission.