-
Notifications
You must be signed in to change notification settings - Fork 162
Create Huffman_Coding.py #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Python implementation of Huffman Coding using Greedy Approach
Python implementation of Huffman Coding using Greedy Approach
@ASHMITA-DE Please look into the file structure. Create a Huffman Coding folder inside Greedy, put your code there.
Implementation of Huffman Coding using Greedy Approach.
@ASHMITA-DE Please look into the file structure. Create a Huffman Coding folder inside Greedy, put your code there.
Done.
@indrarahul2013 , could you please classify the repository as ‘hacktoberfest’ eligible. Thank you.
@indrarahul2013 , as per the new rules of Hacktoberfest 2020, could you please label this pull request as "hacktoberfest-accepted"? Thank you.
Python implementation of Huffman Coding using Greedy Approach
Thank you for your contribution. Please provide the details requested below.
ISSUE NUMBER
#279
SHORT DESCRIPTION
Huffman Coding is a technique of compressing data to reduce its size without loss of data. It is generally useful to compress the data in which there are frequently occurring characters.
It follows a Greedy approach since it deals with generating minimum length prefix-free binary codes.
It uses variable-length encoding scheme for assigning binary codes to characters depending on how frequently they occur in the given text.
Priority Queue is used for building the Huffman tree such that the character that occurs most frequently is assigned the smallest code and the one that occurs least frequently gets the largest code.
It follows this procedure: -
Create a leaf node for each character and build a min heap using all the nodes (The frequency value is used to compare two nodes in min heap)
Repeat Steps 3 to 5 while heap has more than one node
Extract two nodes, say x and y, with minimum frequency from the heap
Create a new internal node z with x as its left child and y as its right child. Also frequency(z)= frequency(x)+frequency(y)
Add z to min heap
Last node in the heap is the root of Huffman tree
TESTING
Just run it on any IDE.