SlideShare a Scribd company logo
1 of 2
Download to read offline
Huffman Code Decoding
Rex Yuan
May 13, 2015
Huffman Code Decoding
We take a sequence to be decoded and a table of corresponding characters and
their probabilities as input. Using the given characters and probabilities, this
algorithm build a binary tree by always selecting the two characters with lowest
probabilities and make them a subtree with the sum of their probabilities. When
going from the root, each traversal to the left subtree represents a ”1” and right
a ”0”.
Time Complexity
Suppose we have a total of m possible character to be encoded and a sequence
with length n to be decoded, the time complexity would be linear with regards
to m and n, n2
+ m, i.e.,
O(n2
)
because in worst case we will iterate through all characters and perform a tree-
building operation which in worst case would resemble a completely un-balanced
tree, and thus produce a recursion tree containing n levels, and the operations
required for each level increments from 1 to n − 1, in turn yielding O(n2
) which
dominates over the operations needed for decoding, m.
Run Time Stats
I created the following table using UNIX POSIX time function and round the
mean time of 10 trials to five digits after decimal point to calculate the time
past. All samples have the ten possible characters to be encoded, that is 0 9.
Variable input length implies the length of the sequence to be decoded.
Run Time Stats
Sample Input Length Huffman Decoding
1 35 0.00031
2 37 0.00858
3 368 0.00902
1
Pseudo Code
Algorithm 1 Huffman Code Decoding Algorithm
procedure DECODE(prob table, seq)
tree = a key-value associating array, with each item’s key the node in that
subtree and value its current sum probability, according to probtable.
code table = an array, with length of the how many characters in
prob table, which maps each code to its corresponding decoded character with
each code initialised as empty strings.
while more than one node in tree do sml sub nodes = key of node with
smallest probability in tree sec sub nodes = key of node with second smallest
probability in tree
for node in sml sub nodes do
code table[node].key = ”1” + code table[node].key
end for
for node in sec sub nodes do
code table[node].key = ”0” + code table[node].key
end for
tree[sml sub nodes + sec sub nodes] = tree[sml sub nodes] +
tree[sec sub nodes]
delete tree[sml sub nodes]
delete tree[sec sub nodes]
end while
temp = ””
result = ””
for code in seq do
temp = temp + code
if temp in code table then
result = result + code table[temp]
temp = ””
end if
end for
return result
end procedure
2

More Related Content

What's hot

Multimedia lossless compression algorithms
Multimedia lossless compression algorithmsMultimedia lossless compression algorithms
Multimedia lossless compression algorithmsMazin Alwaaly
 
Huffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysisHuffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysisRamakant Soni
 
Huffman's Alforithm
Huffman's AlforithmHuffman's Alforithm
Huffman's AlforithmRoohaali
 
Data Communication & Computer network: Shanon fano coding
Data Communication & Computer network: Shanon fano codingData Communication & Computer network: Shanon fano coding
Data Communication & Computer network: Shanon fano codingDr Rajiv Srivastava
 
Noise infotheory1
Noise infotheory1Noise infotheory1
Noise infotheory1vmspraneeth
 
Data Compression - Text Compression - Run Length Encoding
Data Compression - Text Compression - Run Length EncodingData Compression - Text Compression - Run Length Encoding
Data Compression - Text Compression - Run Length EncodingMANISH T I
 
Huffman coding || Huffman Tree
Huffman coding || Huffman TreeHuffman coding || Huffman Tree
Huffman coding || Huffman TreeGurunadh Guru
 
Arithmetic coding
Arithmetic codingArithmetic coding
Arithmetic codingVikas Goyal
 
Arithmetic coding
Arithmetic codingArithmetic coding
Arithmetic coding09lavee
 

What's hot (20)

Huffman coding
Huffman coding Huffman coding
Huffman coding
 
Multimedia lossless compression algorithms
Multimedia lossless compression algorithmsMultimedia lossless compression algorithms
Multimedia lossless compression algorithms
 
Huffman Coding
Huffman CodingHuffman Coding
Huffman Coding
 
Huffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysisHuffman and Arithmetic coding - Performance analysis
Huffman and Arithmetic coding - Performance analysis
 
Huffman's Alforithm
Huffman's AlforithmHuffman's Alforithm
Huffman's Alforithm
 
Huffman coding || Huffman Tree
Huffman coding || Huffman TreeHuffman coding || Huffman Tree
Huffman coding || Huffman Tree
 
Shannon Fano
Shannon FanoShannon Fano
Shannon Fano
 
Huffman Encoding Pr
Huffman Encoding PrHuffman Encoding Pr
Huffman Encoding Pr
 
Lossless
LosslessLossless
Lossless
 
Huffman coding
Huffman codingHuffman coding
Huffman coding
 
Data Communication & Computer network: Shanon fano coding
Data Communication & Computer network: Shanon fano codingData Communication & Computer network: Shanon fano coding
Data Communication & Computer network: Shanon fano coding
 
Huffman Student
Huffman StudentHuffman Student
Huffman Student
 
Noise infotheory1
Noise infotheory1Noise infotheory1
Noise infotheory1
 
Text compression
Text compressionText compression
Text compression
 
Data Compression - Text Compression - Run Length Encoding
Data Compression - Text Compression - Run Length EncodingData Compression - Text Compression - Run Length Encoding
Data Compression - Text Compression - Run Length Encoding
 
Source coding theorem
Source coding theoremSource coding theorem
Source coding theorem
 
Huffman coding || Huffman Tree
Huffman coding || Huffman TreeHuffman coding || Huffman Tree
Huffman coding || Huffman Tree
 
Arithmetic coding
Arithmetic codingArithmetic coding
Arithmetic coding
 
Arithmetic coding
Arithmetic codingArithmetic coding
Arithmetic coding
 
Arithmetic Coding
Arithmetic CodingArithmetic Coding
Arithmetic Coding
 

Similar to Huffman Code Decoding

basicsofcodingtheory-160202182933-converted.pptx
basicsofcodingtheory-160202182933-converted.pptxbasicsofcodingtheory-160202182933-converted.pptx
basicsofcodingtheory-160202182933-converted.pptxupendrabhatt13
 
Neuro genetic key based recursive modulo 2 substitution using mutated charact...
Neuro genetic key based recursive modulo 2 substitution using mutated charact...Neuro genetic key based recursive modulo 2 substitution using mutated charact...
Neuro genetic key based recursive modulo 2 substitution using mutated charact...ijcsity
 
Information Theory and coding - Lecture 3
Information Theory and coding - Lecture 3Information Theory and coding - Lecture 3
Information Theory and coding - Lecture 3Aref35
 
Distributed Coordination
Distributed CoordinationDistributed Coordination
Distributed CoordinationLuis Galárraga
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript ObjectsReem Alattas
 
Huffman&Shannon-multimedia algorithms.ppt
Huffman&Shannon-multimedia algorithms.pptHuffman&Shannon-multimedia algorithms.ppt
Huffman&Shannon-multimedia algorithms.pptPrincessSaro
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II PresentationKnoldus Inc.
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II PresentationKnoldus Inc.
 
Mysql Performance Optimization Indexing Algorithms and Data Structures
Mysql Performance Optimization Indexing Algorithms and Data StructuresMysql Performance Optimization Indexing Algorithms and Data Structures
Mysql Performance Optimization Indexing Algorithms and Data StructuresAbhijit Mondal
 
Lec_8_Image Compression.pdf
Lec_8_Image Compression.pdfLec_8_Image Compression.pdf
Lec_8_Image Compression.pdfnagwaAboElenein
 
art_sklar7_reed-solomon
art_sklar7_reed-solomonart_sklar7_reed-solomon
art_sklar7_reed-solomonAniruddh Tyagi
 

Similar to Huffman Code Decoding (20)

basicsofcodingtheory-160202182933-converted.pptx
basicsofcodingtheory-160202182933-converted.pptxbasicsofcodingtheory-160202182933-converted.pptx
basicsofcodingtheory-160202182933-converted.pptx
 
Neuro genetic key based recursive modulo 2 substitution using mutated charact...
Neuro genetic key based recursive modulo 2 substitution using mutated charact...Neuro genetic key based recursive modulo 2 substitution using mutated charact...
Neuro genetic key based recursive modulo 2 substitution using mutated charact...
 
TeraSort
TeraSortTeraSort
TeraSort
 
Compression Ii
Compression IiCompression Ii
Compression Ii
 
Compression Ii
Compression IiCompression Ii
Compression Ii
 
Information Theory and coding - Lecture 3
Information Theory and coding - Lecture 3Information Theory and coding - Lecture 3
Information Theory and coding - Lecture 3
 
Encoding in sc
Encoding in scEncoding in sc
Encoding in sc
 
Basics of coding theory
Basics of coding theoryBasics of coding theory
Basics of coding theory
 
Distributed Coordination
Distributed CoordinationDistributed Coordination
Distributed Coordination
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
 
Huffman&Shannon-multimedia algorithms.ppt
Huffman&Shannon-multimedia algorithms.pptHuffman&Shannon-multimedia algorithms.ppt
Huffman&Shannon-multimedia algorithms.ppt
 
Komdat-Kompresi Data
Komdat-Kompresi DataKomdat-Kompresi Data
Komdat-Kompresi Data
 
Losseless
LosselessLosseless
Losseless
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II Presentation
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II Presentation
 
Mysql Performance Optimization Indexing Algorithms and Data Structures
Mysql Performance Optimization Indexing Algorithms and Data StructuresMysql Performance Optimization Indexing Algorithms and Data Structures
Mysql Performance Optimization Indexing Algorithms and Data Structures
 
Lec_8_Image Compression.pdf
Lec_8_Image Compression.pdfLec_8_Image Compression.pdf
Lec_8_Image Compression.pdf
 
Hamming codes
Hamming codesHamming codes
Hamming codes
 
Lec-03 Entropy Coding I: Hoffmann & Golomb Codes
Lec-03 Entropy Coding I: Hoffmann & Golomb CodesLec-03 Entropy Coding I: Hoffmann & Golomb Codes
Lec-03 Entropy Coding I: Hoffmann & Golomb Codes
 
art_sklar7_reed-solomon
art_sklar7_reed-solomonart_sklar7_reed-solomon
art_sklar7_reed-solomon
 

More from Rex Yuan

8/9 RLDM for Prosocial Behavior
8/9 RLDM for Prosocial Behavior8/9 RLDM for Prosocial Behavior
8/9 RLDM for Prosocial BehaviorRex Yuan
 
圖文作業
圖文作業圖文作業
圖文作業Rex Yuan
 
A Brief Intro to Chatbot
A Brief Intro to ChatbotA Brief Intro to Chatbot
A Brief Intro to ChatbotRex Yuan
 
A review of consumer brain computer interface devices
A review of consumer brain computer interface devicesA review of consumer brain computer interface devices
A review of consumer brain computer interface devicesRex Yuan
 
CSOP 第一週:上課簡報
CSOP 第一週:上課簡報CSOP 第一週:上課簡報
CSOP 第一週:上課簡報Rex Yuan
 
Maximum Flow
Maximum FlowMaximum Flow
Maximum FlowRex Yuan
 
Box Problem
Box ProblemBox Problem
Box ProblemRex Yuan
 
Longest Common Sequence Algorithm Analysis
Longest Common Sequence Algorithm AnalysisLongest Common Sequence Algorithm Analysis
Longest Common Sequence Algorithm AnalysisRex Yuan
 
Convex Hull Algorithm Analysis
Convex Hull Algorithm AnalysisConvex Hull Algorithm Analysis
Convex Hull Algorithm AnalysisRex Yuan
 
計概:Programming Paradigm (Notes)
計概:Programming Paradigm (Notes)計概:Programming Paradigm (Notes)
計概:Programming Paradigm (Notes)Rex Yuan
 
台灣大學聯盟第一學期
台灣大學聯盟第一學期台灣大學聯盟第一學期
台灣大學聯盟第一學期Rex Yuan
 
Word and Phrases: Improv Everywhere - Gotta Share
Word and Phrases: Improv Everywhere - Gotta ShareWord and Phrases: Improv Everywhere - Gotta Share
Word and Phrases: Improv Everywhere - Gotta ShareRex Yuan
 
計概:Programming Paradigm
計概:Programming Paradigm計概:Programming Paradigm
計概:Programming ParadigmRex Yuan
 
LinkedIn, the Serious Network 繁體中文版
LinkedIn, the Serious Network  繁體中文版LinkedIn, the Serious Network  繁體中文版
LinkedIn, the Serious Network 繁體中文版Rex Yuan
 

More from Rex Yuan (14)

8/9 RLDM for Prosocial Behavior
8/9 RLDM for Prosocial Behavior8/9 RLDM for Prosocial Behavior
8/9 RLDM for Prosocial Behavior
 
圖文作業
圖文作業圖文作業
圖文作業
 
A Brief Intro to Chatbot
A Brief Intro to ChatbotA Brief Intro to Chatbot
A Brief Intro to Chatbot
 
A review of consumer brain computer interface devices
A review of consumer brain computer interface devicesA review of consumer brain computer interface devices
A review of consumer brain computer interface devices
 
CSOP 第一週:上課簡報
CSOP 第一週:上課簡報CSOP 第一週:上課簡報
CSOP 第一週:上課簡報
 
Maximum Flow
Maximum FlowMaximum Flow
Maximum Flow
 
Box Problem
Box ProblemBox Problem
Box Problem
 
Longest Common Sequence Algorithm Analysis
Longest Common Sequence Algorithm AnalysisLongest Common Sequence Algorithm Analysis
Longest Common Sequence Algorithm Analysis
 
Convex Hull Algorithm Analysis
Convex Hull Algorithm AnalysisConvex Hull Algorithm Analysis
Convex Hull Algorithm Analysis
 
計概:Programming Paradigm (Notes)
計概:Programming Paradigm (Notes)計概:Programming Paradigm (Notes)
計概:Programming Paradigm (Notes)
 
台灣大學聯盟第一學期
台灣大學聯盟第一學期台灣大學聯盟第一學期
台灣大學聯盟第一學期
 
Word and Phrases: Improv Everywhere - Gotta Share
Word and Phrases: Improv Everywhere - Gotta ShareWord and Phrases: Improv Everywhere - Gotta Share
Word and Phrases: Improv Everywhere - Gotta Share
 
計概:Programming Paradigm
計概:Programming Paradigm計概:Programming Paradigm
計概:Programming Paradigm
 
LinkedIn, the Serious Network 繁體中文版
LinkedIn, the Serious Network  繁體中文版LinkedIn, the Serious Network  繁體中文版
LinkedIn, the Serious Network 繁體中文版
 

Huffman Code Decoding

  • 1. Huffman Code Decoding Rex Yuan May 13, 2015 Huffman Code Decoding We take a sequence to be decoded and a table of corresponding characters and their probabilities as input. Using the given characters and probabilities, this algorithm build a binary tree by always selecting the two characters with lowest probabilities and make them a subtree with the sum of their probabilities. When going from the root, each traversal to the left subtree represents a ”1” and right a ”0”. Time Complexity Suppose we have a total of m possible character to be encoded and a sequence with length n to be decoded, the time complexity would be linear with regards to m and n, n2 + m, i.e., O(n2 ) because in worst case we will iterate through all characters and perform a tree- building operation which in worst case would resemble a completely un-balanced tree, and thus produce a recursion tree containing n levels, and the operations required for each level increments from 1 to n − 1, in turn yielding O(n2 ) which dominates over the operations needed for decoding, m. Run Time Stats I created the following table using UNIX POSIX time function and round the mean time of 10 trials to five digits after decimal point to calculate the time past. All samples have the ten possible characters to be encoded, that is 0 9. Variable input length implies the length of the sequence to be decoded. Run Time Stats Sample Input Length Huffman Decoding 1 35 0.00031 2 37 0.00858 3 368 0.00902 1
  • 2. Pseudo Code Algorithm 1 Huffman Code Decoding Algorithm procedure DECODE(prob table, seq) tree = a key-value associating array, with each item’s key the node in that subtree and value its current sum probability, according to probtable. code table = an array, with length of the how many characters in prob table, which maps each code to its corresponding decoded character with each code initialised as empty strings. while more than one node in tree do sml sub nodes = key of node with smallest probability in tree sec sub nodes = key of node with second smallest probability in tree for node in sml sub nodes do code table[node].key = ”1” + code table[node].key end for for node in sec sub nodes do code table[node].key = ”0” + code table[node].key end for tree[sml sub nodes + sec sub nodes] = tree[sml sub nodes] + tree[sec sub nodes] delete tree[sml sub nodes] delete tree[sec sub nodes] end while temp = ”” result = ”” for code in seq do temp = temp + code if temp in code table then result = result + code table[temp] temp = ”” end if end for return result end procedure 2