M2_prefixCode
M2_prefixCode
Neena Raj N. R.
January 2024
Syllabus
Module 2
Run length encoding, RLE Text compression, Statistical methods-Prefix
Codes, Binary Huffman coding, Illustration of Binary Huffman coding,
Non-binary Huffman Algorithms, Arithmetic Coding algorithm, Illustration of
Arithmetic Coding algorithm,
Course Outcomes
CO1 Describe the fundamental principles of data Understand
compression.
CO2 Apply
Make use of statistical and dictionary based
compression techniques for various applications
CO3 Illustrate various image compression standards. Apply
CO4 Summarize video compression mechanisms to re- Understand
duce the redundancy in video.
CO5 Use the fundamental properties of digital audio Understand
to compress audio data.
Coding
Coding
Coding
Coding
The average length of the code is not the only important point in
designing a “good” code.
The selection of codewords for different messages or symbols xi , is
done according to the following two considerations:
1 The average code length L must be as minimum as possible.
L = Σni=1 li p(xi ) bits/message or bits/symbol
where l is the length of the codeword for message or symbol xi (li is in
bits for binary coding, or in digits for nonbinary coding).
2 The codewords at the receiver must be uniquely decodable. Uniquely
decodable means that any codeword for any symbol( or message) must
not be the beginning from the left for any other codeword of higher
length.
Coding
Coding
Statistical Methods
Statistical Methods
Statistical Methods
Consider the following variable size code
Exercises
1 Consider the four different codes for four letter alphabet as shown in
table
Exercises
Exercises
Exercises
Exercises
Exercises
Solution:
Prefix and Dangling suffix:
Suppose we have two binary codewords a and b, where a is k bits long,
b is n bits long, and k < n. If the first k bits of b are identical to a,
then a is called a prefix of b. The last n - k bits of b are called the
dangling suffix.
For example, if a = 010 and b = 01011, then a is a prefix of b and the
dangling suffix is 11.
Test for Uniquely Decodable Codes
Construct a list of all the codewords.
Examine all pairs of codewords to see if any codeword is a prefix of
another codeword.
Exercises
Whenever you find such a pair, add the dangling suffix to the list unless
you have added the same dangling suffix to the list in a previous
iteration.
Now repeat the procedure using this larger list. Continue in this
fashion until one of the following two things happens:
1 You get a dangling suffix that is a codeword.
2 There are no more unique dangling suffixes.
If you get the first outcome, the code is not uniquely decodable.
However, if you get the second outcome, the code is uniquely
decodable.
Exercises
Exercises
Exercises
Prefix Codes
Prefix Codes
Prefix Codes
Prefix Codes
Note that apart from the root node, the trees have two kinds of
nodes—nodes that give rise to other nodes and nodes that do not.
The first kind of nodes are called internal nodes, and the second kind
are called external nodes or leaves.
In a prefix code, the codewords are only associated with the external
nodes.
A code that is not a prefix code will have codewords associated with
internal nodes.
Prefix Codes
Prefix Codes
The code for any symbol can be obtained by traversing the tree from
the root to the external node corresponding to that symbol.
Each branch on the way contributes a bit to the codeword: a 0 for
each left branch and a 1 for each right branch.
Prefix Codes
Prefix Codes
Prefix Codes
Prefix Codes
Prefix Codes
Module 2
Run length encoding, RLE Text compression, Statistical methods-Prefix
Codes, Binary Huffman coding, Illustration of Binary Huffman coding,
Non-binary Huffman Algorithms, Arithmetic Coding algorithm, Illustration of
Arithmetic Coding algorithm,
Course Outcomes
CO1 Describe the fundamental principles of data Understand
compression.
CO2 Apply
Make use of statistical and dictionary based
compression techniques for various applications
CO3 Illustrate various image compression standards. Apply
CO4 Summarize video compression mechanisms to re- Understand
duce the redundancy in video.
CO5 Use the fundamental properties of digital audio Understand
to compress audio data.
References