# Løsningsforslag, Ukeoppgaver nr 9 INF2310, våren 2007. Assignment 1: Arithmetic Coding ```L&oslash;sningsforslag, Ukeoppgaver nr 9 INF2310,
v&aring;ren 2007.
Assignment 1: Arithmetic Coding
Huffman coding and the like use an integer number (k) of bits for each symbol, hence k is never
less than 1. Sometimes, e.g., when sending a 1-bit image, compression becomes impossible.
Suppose that the alphabet is X and Y (alias 0 and 1), and that the normalized probability of X is
known. Show how you can generate codewords of unequal length for all the possible 2-symbol
messages, and find the bit-pattern for each codeword, given that p(X) =2/3.
If p(x) = 2/3, then p(Y) =1-p(X) = 1/3
If we are only concerned with encoding length 2 messages, then we can map all possible
messages of length 2 onto intervals in the range [0..1] as shown below
To encode any one of the four possible length 2 message, just send enough bits of a binary
fraction that uniquely specifies the proper interval. A solution is as follows:
Similarly, map all possible length 3 messages to intervals in the range [0..1], and find the
codewords for all possible messages of length 3.
How would you encode X Y X X Y X ? Do you get any compression?
Pairwise compression gives 7 bits instead of 6. Triplets give 6 bits. So we need longer sequences
to gain anything.
Is there a relation between the width of the intervals and the number of bits used to encode them?