0% found this document useful (0 votes)
2 views

CS301_Assignment-2

The document presents an assignment focused on data structures, specifically involving a string and its transmission over a network. It includes tasks to build a frequency table and a Huffman encoding tree, along with calculations for bits used with and without encoding. The assignment concludes with a percentage calculation showing that Huffman encoding saves approximately 48.56% of bits compared to fixed-length encoding.

Uploaded by

rereva7383
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

CS301_Assignment-2

The document presents an assignment focused on data structures, specifically involving a string and its transmission over a network. It includes tasks to build a frequency table and a Huffman encoding tree, along with calculations for bits used with and without encoding. The assignment concludes with a percentage calculation showing that Huffman encoding saves approximately 48.56% of bits compared to fixed-length encoding.

Uploaded by

rereva7383
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment No.

02
Name: Nabeel Ahmed
SEMESTER Spring 2024
CS301- Data Structures ID: BC230428531

Question. No. 1 Solutions:

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]


Use the following sample frequency table:

Character D a t Space S r u c e i s o n f h B ( C ) p g m .
Frequency 1 3 4 10 3 6 3 3 5 1 4 6 1 2 1 1 1 1 1 1 1 1 1
Number 8 24 32 80 24 48 24 24 40 8 32 48 8 16 8 8 8 8 8 8 8 8 8
of Bits
used
without
any
encoding
Huffman
100110

11111

0111

110

0100

000

0101

0110

1110

100111

1000

001

101000

10010

101001

101010

101011

101100

101101

101110

101111

111100

111101
code of
each
character
Number
of Bits
used with 6 15 16 30 12 18 12 12 20 6 16 18 6 10 6 6 6 6 6 6 6 6 6
Huffman
encoding

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

Q:1 - Without using any encoding technique = 488 bits


Q:2 - With Huffman encoding technique = 251 bits
Q:3 - What percentage of bits is saved by Huffman encoding scheme?
Percentage = (Fixed length bits – Encoding bits ÷ Fixed length bits)
((488 -251) ÷ 488) * 100 = 48.56 % bits saved

You might also like