Huffman Coding

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 11

HUFFMAN CODING

FILE COMPRESSION
AND DECOMPRESSION
Huffman coding is a popular method for lossless data compression, used in
file encoding and decoding.
HUFFMANCODIN
G
T E A M M AT E S :

SUBHASH J (RA2212703010006)
RAMESH KANNA S (RA2212703010011)
Basics of File Encoding and
Decoding

Huffman coding is a lossless data compression algorithm. The


idea is to assign variable-length codes to input characters,
lengths of the assigned codes are based on the frequencies of
corresponding characters.
The variable-length codes assigned to input characters are
Prefix Codes, means the codes (bit sequences) are assigned in
such a way that the code assigned to one character is not the
prefix of code assigned to any other character.
What is Huffman coding?

Lossless Data Compression Variable Length Encoding


Huffman coding is a technique used for lossless It assigns variable-length codes to different
data compression, which reduces the size of files characters, with shorter codes for more frequently
without losing any data. occurring characters.

Efficient Data Storage Widely Used in File Compression


This method optimizes the storage of data by Huffman coding is widely used in file compression
representing frequently occurring characters with algorithms and in applications that require efficient
shorter codes, reducing the overall file size. data storage and transmission.
How does Huffman coding work?
Step 1: Frequency Analysis
The algorithm reads the input file to calculate the frequency of each character.

2 Step 2: Building the Huffman Tree


The algorithm constructs a binary tree using a min-heap to create the optimal prefix code.

3 Step 3: Generating Huffman Codes


Assigns unique binary codes to each character based on the Huffman tree structure.
Steps involved in Huffman coding
Frequency Calculation
Determine the frequency of each character in the input data.

Priority Queue
2
Create a priority queue based on the frequency of characters.

Huffman Tree Construction


3 Build the Huffman tree using the characters' frequency as the key.

Code Assignment
4 Assign binary codes to each character based on the tree
structure.
Building the Huffman tree
The process of building a Huffman tree involves creating
a binary tree structure.

• Start with all the characters and their frequencies


as individual nodes.

• Merge the two nodes with the lowest frequencies


to form a new internal node.

• Repeat the merging process until all nodes are


part of the Huffman tree.
Encoding a file using Huffman coding

Step 1: Frequency Table


Create a frequency table for all the characters in the file.

Step 2: Build Huffman Tree


Construct a Huffman tree based on the frequency of characters.

Step 3: Generate Codes


Assign codes to each character based on the Huffman tree.
Decoding a File Using Huffman Coding
Understanding Huffman Reconstructing the Original Efficiency and Accuracy
Decoding Data
The decoded data retains its
Huffman decoding is the process During decoding, the Huffman tree accuracy and consumes minimal
of converting coded data using the is used to reconstruct the original storage space, making Huffman
Huffman algorithm back into its data from the encoded bitstream. coding efficient for file
original form. compression.
Advantages of Huffman coding

Efficient Fast Encoding & Preservation of Data Reduction in Storage


Compression Decoding Requirements
Huffman coding provides It allows for quick Ensures preservation of
efficient compression, encoding and decoding of original data during Minimizes storage
minimizing file size. files. compression and requirements, especially
decompression. for large volumes of data.
Conclusion :

Efficient Compression: Huffman coding allows for efficient data compression,


reducing file sizes significantly.

Optimized Encoding: The method prioritizes frequently used characters or


symbols for smaller encodings.

Decoding Process: Huffman decoding helps in retrieving the original data from
the compressed file seamlessly.

Widely Used: Used in various applications, including image and video


compression, and data transmission.

You might also like