CS301 Assignment 2 Solution
CS301 Assignment 2 Solution
CS301 Assignment 2 Solution
Ali Hamza
Answer:
Characte D a t S S r u c e s i o n f h B C ( ) p g m .
r
P
Frequenc 1 3 4 10 3 6 3 3 5 4 1 6 1 2 1 1 1 1 1 1 1 1 1
y
Number 8 2 3 80 2 4 2 2 4 3 8 4 8 1 8 8 8 8 8 8 8 8 8
of Bits 4 2 4 8 4 4 0 2 8 6
used
without
any
encoding
Huffman
000000
00101
1011
11
01001
0101
01101
1001
0011
0001
000001
0111
001001
00001
001000
010000
010001
011000
011001
10000
10001
10100
10101
code of
each
character
Number
of Bits
used 6
6 15 16 20 15 24 15 12 20 16 6 24 6 10 6 6 6 6 5 5 5 5
with
Huffman
encoding
Number of Bits used without any encoding = 61 * 8 = 488 Bits
6+15+16+20+15+24+15+12+20+16+6+24+6+10+6+6+6+6+6+5+5+5+5 =
255 Bits
B. Calculate how many bits will be used for the above string: