Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

ASSIGNMENT NUMBER 2 :

CS301

STUDENT ID BC210404717

STUDENT OF BSCS

QUESTION:

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.

String: “Data Structures is one of the core courses of BS(CS) program.”

Note: Double quotes are not the part of string.

a. Build frequency table and Huffman encoding tree. [14 Marks]

Answer:

Use the following sample frequency table:

Chara D a t S r u c e s i o n f h B ( C ) p g m Spa .
cter
ce
Frequ 1 3 4 3 6 3 3 5 4 1 6 1 2 1 1 1 1 1 1 1 1 10 1
ency
Numb 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
er of
Bits
used
witho
ut any
encodi
ng
Huffm
000000
00101
1011
01001
0101
10101
1001
0011
0001
000001
0111
001001
00001
001000
010000
011000
010001
011001
10000
10001
10100

11

10101
an
code
of
each
charac
ter
Numb
er of
Bits
used
1 1 1 2 1 2 2 1 2 1
with 6 6 6 6 6 6 6 6 5 5 5 20 5
5 6 5 4 5 4 0 6 4 0
Huffm
an
encodi
ng

b. Calculate how many bits will be used for the above string:

 Without using any encoding technique?

ANSWER:

Number of bits without any coding technique =61*8=488 bits

 With Huffman encoding technique ?

Answer:

Number of bits by using Huffman encoding technique =267 bits

 What percentage of bits is saved by Huffman encoding scheme?

Answer:

Percentage=((488-267)/488)*100=45.28%

You might also like