Assignment 01 of CS502: Submitted By: Ayesha Azad VU ID: BC190401240 Submitted To: Instructor
Assignment 01 of CS502: Submitted By: Ayesha Azad VU ID: BC190401240 Submitted To: Instructor
VU ID: BC190401240
Question 01:
You are required to find the time complexity of the following codes with respect to worst
case.
Part A:
for (i=1;i<=n2;i++)
for(i=0;i<=n2;i++)
for(i=0;i<=n3;i++)
a=x+y;
Part B:
for(y=0;y<=n;y++)
for(i=0;i<=n2;i++)
{
for(i=0;i<=n3;i++)
a=x+y;
Answer Part A:
Complexity with respect to worst case = T(n) = number of times each loop runs
T(n) = n X n2 X n3 +c
T(n) = n1+2+3 +c
T(n) = n6 +c
T(n) = n6
Answer Part B:
Complexity with respect to worst case = T(n) = number of times each loop runs
T(n) = n X n2 X n3 + c
T(n) = n1+2+3 + c
T(n) = n6 +c
T(n) = n6
Question No 02:
Write a simple algorithm (Only Pseudo code) about making 3x3 matrix table and also calculate
the worst case time complexity T(n).
1 2 3
4 5 6
7 8 9
Answer:
Pseudo Code:
for 1 to noOfRows
for 1 to noOfColumns
Matrix[rows][columns]
Time Complexity:
T(n) = n X n +c
T(n) = n2 +c
T(n) = n2