S 2
S 2
IMPLEMENTATION
By :
Vidushi Bindroo 17115
Garvita Rana 17105
ABSTRACT
Given
● A set of symbols and their weights (usually proportional to probabilities
or equal to their frequencies).
Find
● A prefix-free binary code (a set of codewords) with minimum expected
codeword length (equivalently, a tree with minimum weighted path
length from the root).
The simplest construction algorithm uses a priority queue where the node with lowest
probability is given highest priority:
Step 1:- Create a leaf node for each symbol and add it to the priority queue
(i.e. Create a min heap of Binary trees and heapify it).
Step 2:- While there is more than one node in the queue (i.e. min heap):
i. Remove the two nodes of highest priority (lowest probability or lowest
frequency ) from the queue.
ii. Create a new internal node with these two nodes as children and with
probability equal to the sum of the two nodes' probabilities (frequencies).
iii. Add the new node to the queue.
Step 3:- The remaining node is the root node and the Huffman tree is complete.
4. References
Sartaj Sahani: Data structures, Algorithms and Applications in C++
http://www.itl.nist.gov/div897/sqg/dads/HTML/codingTree.html
http://encyclopedia2.thefreedictionary.com/Huffman+tree
http://en.wikipedia.org/wiki/Huffman_coding