0% found this document useful (0 votes)
14 views3 pages

Assignment 01 of CS502: Submitted By: Ayesha Azad VU ID: BC190401240 Submitted To: Instructor

alogsss

Uploaded by

Ayesha azad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Assignment 01 of CS502: Submitted By: Ayesha Azad VU ID: BC190401240 Submitted To: Instructor

alogsss

Uploaded by

Ayesha azad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Assignment 01 of CS502

Submitted by: Ayesha Azad

VU ID: BC190401240

Submitted to: Instructor

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:

Matrix( rows, columns)

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

You might also like