Lecture 4
Lecture 4
04/02/2024 1
Coding
• Assignment of binary sequences to elements of an alphabet.
• The set of binary sequences is called a code, and the individual
members of the set are called codewords.
• An alphabet is a collection of symbols called letters
• For example, the alphabet used in writing most books consists of
the 26 lowercase letters, 26 uppercase letters, and a variety of
punctuation marks.
• ASCII code uses the same number of bits to represent each symbol.
Such a code is called a fixed-length code.
• fewer bits to represent symbols that occur more often, on the
average we would use fewer bits per symbol.
• The average number of bits per symbol is often called the rate of
the code.
04/02/2024 2
Uniquely Decodable Codes
• The average length of the code is not the only
important point in designing a “good” code
4
04/02/2024
Received String Decoding Rule
04/02/2024 6
Test for Unique Decodability
• 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.
• Construct a list of all the codewords.
• Examine all pairs of codewords to see if any codeword is a prefix of
another codeword.
• 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.
04/02/2024 7
Contd…
• 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.
04/02/2024 8
Example
04/02/2024 9
Prefix Codes
• Unique decodability requires examining the dangling suffixes
initially generated by codeword pairs in which one codeword is the
prefix of the other.
• If the dangling suffix is itself a codeword, then the code is not
uniquely decodable.
• A code in which no codeword is a prefix to another codeword is
called a prefix code.
• A simple way to check if a code is a prefix code is to draw the
rooted binary tree corresponding to the code. Draw a tree that
starts from a single node (the root node) and has a maximum of
two possible branches at each node.
04/02/2024 10
Codes and The Corresponding Binary Tree
•In a prefix code, the codewords
are only associated with the
external nodes
•A code that is not a prefix code,
such as Code 4, will have
codewords associated with
internal nodes.
04/02/2024 11
The Kraft-McMillan Inequality
• For any nonprefix uniquely decodable code,
we can always find a prefix code with the
same codeword lengths
04/02/2024 12
Proof
04/02/2024 13
This part of the Kraft-McMillan inequality provides a necessary
condition for uniquely decodable codes. That is, if a code is
uniquely decodable, the codeword lengths have to satisfy the
inequality.
04/02/2024 14
04/02/2024 15
04/02/2024 16
04/02/2024 17