0% found this document useful (0 votes)
10 views1 page

Shanon - Fannon Compression

How the Shannon fanon compression algorithm done

Uploaded by

redmonter John
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Shanon - Fannon Compression

How the Shannon fanon compression algorithm done

Uploaded by

redmonter John
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Write a python program which accept the text data like word, sentence or phrases from the user

then
compress and decompress it using Shannon-fanon compression algorithm model. The program then
must show the tree structure of the compressed data. For example, if the user insert the word hello

The system must perform by this step:

1. Calculate the frequencies of each of the symbols in the list.


2. Sort the list in (decreasing) order of frequencies.
3. Divide the list into two half’s, with the total frequency counts of each half
being as close as possible to the other.
4. The right half is assigned a code of 0 and the left half with a code of 1.
5. Recursively apply steps 3 and 4 to each of the halves, until each symbol has become a

corresponding code leaf on a tree .


The tree diagram must look this the hello
Frequency
l:2
h:1
e:1
o:1
First he divide into 2

then on the left side of the tree we


5
we assign 0 and on the right

side 1
2 3
the we get

l:0 L h,e,o

h:10

e:110 1 2

o:111 h e,o

e 1 o
1

You might also like