You are on page 1of 5

Assignment No.

02 (Solution)
Total Marks: 20
Fall 2023
CS502- Fundamentals of Algorithms Due Date: 10-01-2024

Instructions
Please read the following instructions carefully before solving & submitting assignment:
It should be clear that your assignment will not get any credit (zero marks) if:
 The assignment is submitted after due date.
 The submitted assignment is other than MS Word file.
 The submitted assignment does NOT open or file is corrupted.
 The assignment is copied (from other student or ditto copy from handouts or internet).

Uploading instructions
For clarity and simplicity, you are required to upload/submit only one .doc/docx file.

Objectives
The objectives of this assignment are;

 To be able to understand the basic of Graph.


 To be able to understand the concept of greedy Algorithms using Hamman encoding.

For any query about the assignment, contact at CS502@vu.edu.pk

Good Luck!
Question No. 1 Marks: 10
The following Graph shows the road connections among four cities labeled as A, B, C, and D. Your task is to
create both an adjacency matrix and an adjacency list to accurately represent it.

C
Answer:
Question No. 2 Marks: 10
Consider the string “babcbda”. You are required to do the following tasks:
1. How many Bits are required to encode the above string using 8-bit ASCII?
2. Calculate the frequencies of each character and draw a Huffman Encoding tree to fill the following table.
3. How many Bits are required to encode the above string using variable length codes (Prefix Code).

Letter Frequency Prefix Code

Answer:

1. Total bits are required to encode the above string using 8-bit ASCII = 7*8 bits = 56 bits

2.

Letter Frequency Prefix Code

a 2 10

b 3 0

c 1 110

d 1 111

Huffman Encodding Tree:


3. Bits required to encode the above string using variable length codes 0100110011110 = 13 bits

Lectures Covered: Lecture No. 24 to 28.

Deadline: Your assignment must be uploaded / submitted on or before January 10, 2024
Total Marks: 20

You might also like