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

Cs 301 Assignment 02

Uploaded by

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

Cs 301 Assignment 02

Uploaded by

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

Assignment No.

02
Total Marks: 20
SEMESTER Spring 2024
Lectures Covered:25-26
CS301- Data Structures 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]

Ans Solution (a)


Now

Use the following sample frequency table:

Character D a t space S r u c e s i o n f h B ( C ) p g m .
Frequency 1 3 4 10 3 6 3 3 5 4 1 6 1 2 1 1 1 1 1 1 1 1 1
Number 8 24 32 80 24 48 24 24 40 32 8 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

1000

100111

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 16 6 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?

Ans
:

 Without encoding: 472 bits


 With estimated Huffman encoding: 295 bits
 Percentage of bits saved: Approximately 37.5%

Wish you Best of Luck!

You might also like