0% found this document useful (0 votes)
57 views8 pages

S 2

This document discusses Huffman coding and its implementation. Huffman coding is a lossless data compression algorithm that converts characters into variable length bit strings, with most frequent characters having shorter bit strings. It represents the codes as a binary tree called a Huffman tree. To implement Huffman coding, symbols and their weights are given. Nodes with lowest probability are prioritized in a min heap. Nodes are combined and added to the heap until a root node remains, giving the Huffman tree and codes.

Uploaded by

Vidushi Bindroo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views8 pages

S 2

This document discusses Huffman coding and its implementation. Huffman coding is a lossless data compression algorithm that converts characters into variable length bit strings, with most frequent characters having shorter bit strings. It represents the codes as a binary tree called a Huffman tree. To implement Huffman coding, symbols and their weights are given. Nodes with lowest probability are prioritized in a min heap. Nodes are combined and added to the heap until a root node remains, giving the Huffman tree and codes.

Uploaded by

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

HUFFMAN CODES AND ITS

IMPLEMENTATION
By :
Vidushi Bindroo 17115
Garvita Rana 17105
ABSTRACT

Huffman Coding is an approach to text compression originally developed


by David A. Huffman while he was a Ph.D. student at MIT, and
published in the 1952 paper "A Method for the Construction of
Minimum-Redundancy Codes". In computer science and information
theory, it is one of many lossless data compression algorithms. It is a
statistical compression method that converts characters into variable
length bit strings and produces a prefix code. Most-frequently occurring
characters are converted to shortest bit strings; least frequent, the
longest.
CONTENTS
1. Introduction to Huffman Codes
2. Basic Techniques
3. Implementation of Huffman Coding
a. Program
b. Output(DEMO)
4. References
Huffman was able to design the
1. Introduction most efficient compression
method of this type: no other
to Huffman mapping of individual source
symbols to unique strings of
Coding: bits(i.e. codes) will require
lesser space for storing a piece
of text when the actual symbol
frequencies agree with those
used to create the code.
2. Basic Technique:
In Huffman Coding , the complete set of
codes can be represented as a binary tree,
known as a Huffman tree. This Huffman
tree is also a coding tree i.e. a full binary
tree in which each leaf is an encoded
symbol and the path from the root to a leaf
is its codeword. By convention, bit '0'
represents following the left child and bit
'1' represents following the right child.
One code bit represents each level. Thus
more frequent characters are near the root
and are coded with few bits, and rare
characters are far from the root and are
coded with many bits.
PROBLEM DEFINITION:-

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

You might also like