Department of Computer Science & Information Technology,
University of Engineering & Technology Peshawar.
Data Structures and Algorithms (Fall 2020) Assignment 01
Due Date: Dec 20, 2020 Total Points : 10
Important:
• Only assignments submitted via Google Classroom will be accepted.
• Only typed submission in MS Word or pdf (generated from MS Word) will be accepted.
• The assignment has 2 pages.
Question 1 Why Data Structure? 02 Points
Why it is important to study “Data Structures”? Give at least 3 examples from computer science where
data structures play an important role. (Note: Do not use examples from lecture slides)
Question 2 Time Complexity of Algorithms 03 Points
Analyse and derive the worst-case time complexity of the following algorithm.
Algorithm 1 Algorithm to find the sum of all elements of a matrix of size n x m
1: procedure MatElementsSum(A[0 . . . n − 1, 0, . . . m − 1])
2: sum = 0
3: for i = 0 to n − 1 do
4: for j = 0 to m − 1 do
5: sum = sum + A[i, j]
6: end for
7: end for
8: return sum
9: end procedure
1
Question 3 Time Complexity of Algorithms 03 Points
Consider the following FindSum procedure.
Algorithm 2 A Mysterious Sum Algorithm
1: procedure FindSum( )
2: sum = 0.
3: I = 10.
4: N = 100.
5: while I ≤ N do
6: sum = sum + I.
7: N = N/2.
8: end while
9: return sum.
10: end procedure
i What is the out put of the FindSum procedure?
ii Analyse and derive the worst-case time complexity of FindSum procedure.
Question 4 Optimum Size of Arrays 02 Points
You are asked to write a program for marks obtained by students in the Department of CS & IT (DoCSIT).
The department has 300 students (fixed size) and each student is assigned marks in the range [0, 100].
The management is interested to find the frequency of marks where student marks are greater than 60.
You are allowed to use arrays to store the frequency. What will be the optimum size of the array to store
the frequency? Justify your answer.
Good Luck.