Assignment CS 301
Assignment CS 301
ASSIGNEMENT NO 02
Question No 01 Marks:20
Consider the following string saved into a string type variable. We want
to send it over the network to another computer. Use the given string
and answer (solve) the questions given below.
Character D a t S r u c e s i o f h B C ( ) p g m .
Frequency 1 3 3 3 6 3 3 4 3 1 6 2 1 1 1 1 1 1 1 1 1
Number 8 24 24 24 48 2 24 32 24 8 48 16 8 8 8 8 8 8 8 8 8
of Bits 4
used
without
any
encoding
Huffman 1 1 1 1 1 1 1 1 1 1 0 11 1 1 1 11 111 11 111 111 11
code of
each
1 0 0 1 0 1 1 0 1 10 1 1 1 10 100 10 001 010 11
character 1 0 1 1 1 1 1 0 0 00 1 0 0 11 0 10 0 0 00
0 1 1 0 1 0 1 1 0 1 1 1 1 11
0 1 1 0 0 0 1 1
0 1 0 0 1 0 1
0 0 1 0
0
Number
of Bits
used with 7 3 4 8 4 7 7 4 1 5 1 7 7 6 7 7 7 7 7 7 8
Huffman
encoding
b. Calculate how many bits will be used for the above string:
[6 Marks]
1. Without using any encoding technique
2. With Huffman encoding technique
3. What percentage of bits is saved by Huffman encoding
scheme?
Without using any encoding technique?
Sum the frequencies of each individual characters.
1+3+3+3+6+3+3+4+3+1+6+2+1+1+1+1+1+1+1+1+1=47
So, find the total number of bits without encoding:
47x8=141