Shannon-Fano Algorithm for Data Compression6 Feb 2025 | 4 min read IntroductionEffective data compression is essential for lowering storage needs and bandwidth usage in the field of data processing & transmission. To achieve this, numerous algorithms have been created; the Shannon-Fano algorithm was among the first to be created. This algorithm, which was made during the 1940s by Robert Fano and Claude Shannon, was set up for later improvements in data compression techniques. The method of shrinking a data record to such an extent that it occupies less disk space or requires less resources to send is known as data compression. It tends to be generally partitioned into two classes: lossy compression, in which some data is lost during compression, and lossless compression, in which the original data can be perfectly reproduced from the compressed data. Since the Shannon-Fano technique is a lossless compression methodology, it is utilized in circumstances where it is vital to keep up with the entirety of the data. An Understanding of the Algorithm Shannon-FanoThe Shannon-Fano algorithm functions by analyzing how frequently certain symbols appear in the input data. It uses a systematic process to compress data by giving more often occurring symbols shorter codewords. This is the algorithm broken down step-by-step:
Shannon-Fano Compression ExampleLet's look at a little example to demonstrate the Shannon-Fano algorithm. Take a look at the incoming data below: Input Data: "ABBCCCDDDDEEEEE" Step 1: Analysis of Frequency Symbol frequency: A: 1 B: 2 C: 3 D: 4 E: 5 Step 2: Sorting Symbols Put symbols in order of frequency: E, D, C, B, A Step 3: Partitioning Divide the characters into two groups that have roughly equal frequencies: Set 1: E, D (frequency: 9) Set 2: C, B, A (frequency: 6) Step 4: Assigning Codewords Put '0' to Set 1 symbols and '1' to Set 2 symbols. Set 2: D: 0 E: 0 C: 10 B: 11 A: 12 Step 5: Compression Utilizing the supplied codewords, encrypt the input data: "001110111112222222222" is the compressed data. Code Output: ![]() Code Explanation
ConclusionThe Shannon-Fano algorithm offers a fundamental comprehension of strategies for data compression. The Shannon-Fano method, which prioritizes symbols according to their frequencies, continues to be a fundamental component in the development of data compression. Next TopicSort-a-linked-list-of-0s-1s-and-2s |
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India
