An open API service indexing awesome lists of open source software.

https://github.com/rajatm544/shannon-encoding


https://github.com/rajatm544/shannon-encoding

Last synced: 8 months ago
JSON representation

Awesome Lists containing this project

README

          

# Program to perform Shannon Encoding

- Meant for an assignment, this is a python program that takes a string to encode and returns the code for each symbol in that string
- The encoding is performed using Shannon Binary encoding. The algorithm for the process is as follows:
1. Input a string of characters
2. Compute the frequency of each character, and use that to compute its probability
3. Sort the list of unique characters, in decreasing order of their probabilties.
4. Create a list of αi values, which is the same as the cumulative sum of each probabilty.
5. Find the length of each encoded word, using the formula 2li ≥ 1/(pi).
6. The binary Shannon code for each symbol is the same as the binary representation of its αi value, upto li length.
7. Find the values for the entropy, efficiency, average length and redundancy of the calculated codes.