0% found this document useful (0 votes)
6 views1 page

Question Cs502

Uploaded by

hamadhseeb
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)
6 views1 page

Question Cs502

Uploaded by

hamadhseeb
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/ 1

CS 502 Assignment Solution

BC210207303
 The objectives of this assignment are;

 To give basic knowledge and understanding of asymptotic growth.


 To be able to understand and calculate the complexity of algorithms.

Solution:

Int n= arr.size(); O(1)

//First loop: print each element of the array

for (int I = 0; I < n; ++i) { O(n)

std::cout << arr[i] << std::endl; O(n)

// Second nested loops: print the product of each triplet of elements

for (int j = 0; j < n; ++j) { O(n3 )

for (int k = 0; k < n; ++k) { O(n3 )

for (int 1q = 0; 1 < n; ++1) { O(n3 )

std::cout << arr[j] * arr[k] * arr[1] << std::endl; O(n3 )

The overall time complexity of the given code is:

O(n3 )

You might also like