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

Spring 2024 - CS301 - 2

Uploaded by

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

Spring 2024 - CS301 - 2

Uploaded by

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

Assignment No.

02
Total Marks: 20
SEMESTER Spring 2024
Lectures Covered:25-
CS301- Data Structures 26
Due Date: 24th June,
2024
Instructions
Please read the following instructions carefully before solving & submitting assignment:
It should be clear that your assignment will not get any credit (marks) if:
 The assignment is submitted after due date.
 The submitted assignment file is not in .doc or .docx format.
 The submitted assignment file does not open or corrupted.
 The assignment is copied (from other student or ditto copy from handouts or internet).
Uploading instructions
 Do not wait for grace day. Grace Day is given only if there is problem with LMS on due date. Submit
your solution within due date.
 Note that no assignment will be accepted through email if there is any problem in LMS on grace day.

Objective
The objective of this assignment is

 To get hands on practice of constructing frequency table and Huffman encoding tree.

For any query about the assignment, contact at [email protected]

Marks: 20
Question. No. 1:

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
Frequency
Number of
Bits used
without
any
encoding

Huffman
code of
each
character
Number of
Bits used
with
Huffman
encoding

b. Calculate how many bits will be used for the above string: [6 Marks]
 Without using any encoding technique
 With Huffman encoding technique
 What percentage of bits is saved by Huffman encoding scheme?

Wish you Best of Luck!

Student id :bc230415869

Solution :
Id :bc230415869

Haffman encoding tree:

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 3 5 1 4 6 1 2 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: [6 Marks]
 Without using any encoding technique
 With Huffman encoding technique
What percentage of bits is saved by Huffman encoding scheme?

Solution :
Without using any encoding technique 61* 8 = 488 bits
With Huffman encoding technique = 251 bits

Question: What percentage of bits is saved by Huffman encoding scheme?

Answer: Percentage = (fixed length bits – encoding bits/ fixed length bits ) / 100

After solving : ((488-251) /488) / 100

= 48.56% bits saved

You might also like