Huffman Decoding
Huffman Decoding
PROBLEM STATEMENT
Binary tree:
In a binary tree, each node can have a maximum of two
children linked to it. Some common types of binary trees
include full binary trees, complete binary trees, balanced
binary trees, and degenerate or pathological binary trees.
Ternary Tree:
A Ternary Tree is a tree data structure in which each node
has at most three child nodes, usually distinguished as “left”,
“mid” and “right”.
N-ary Tree or Generic Tree:
Generic trees are a collection of nodes where each node
is a data structure that consists of records and a list of
references to its children(duplicate references are not allowed).
Unlike the linked list, each node stores the address of multiple
nodes.
BINARY TREE
File Systems: Binary trees are used in file systems to organize and store files.
Search Engines: Binary trees are used in search engines to organize and index web pages.
Searching and Sorting Algorithms.
• Expression Trees.
• Decision Trees: Binary trees can be used to implement decision trees, a type of machine learning
algorithm used for classification and regression analysis.
• Huffman Coding:
It is a data compression algorithm that uses binary trees to encode characters. The binary tree used in
Huffman coding is called a Huffman tree, and it is a binary tree in which the nodes represent the
characters to be encoded. The algorithm assigns variable-length characters to each character, and the
most frequent characters receive short codes.
HUFFMAN DECODING
SOURCE CODE:
//Header files
#include <stdio.h>
#include <stdlib.h>
int main()
{
// Example Huffman tree creation
Node* root = create_node(‘\0’);
root->left = create_node(‘\0’);
root->right = create_node(‘A’);
root->left->left = create_node(‘B’);
root->left->right = create_node(‘C’);
return 0;
}
Now let’s see how the code works
S=“1001011”
Processing the string from left to right.
S[0]=‘1’: we move to the right child of the root. We encounter a leaf node with value ‘A’. We add ‘A’ to the decoded
string. We move back to the root.
S[1]=‘0’ : we move to the left child.
S[2]=‘0’:we move to the left child. We encounter a leaf node with value ‘B’. We add ‘B’ to the decoded string. We move
back to the root.
S[3] =‘1’: we move to the right child of the root. We encounter a leaf node with value ‘A’. We add ‘A’ to the
decoded string. We move back to the root.
S[4]=‘1’: we move to the right child of the root. We encounter a leaf node with value ‘A’. We add ‘A’ to the
decoded string. We move back to the root.
S[6] = ‘1’: we move to the right child of the root. We encounter a leaf node with value ‘C’. We add ‘C’ to the
decoded string. We move back to the root.