0% found this document useful (0 votes)
7 views

Assignment 504

try try again

Uploaded by

iqrashafiq9751
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Assignment 504

try try again

Uploaded by

iqrashafiq9751
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Std Bc210402535

Assignment CS502

Solution ;

Question No. 1

Consider the following piece of code of a function that processes a list of integers in the followin
g way:

int n = arr.size(); // Step 1 o(1)

// First loop: print each element of the array

for (int i = 0; i < n; ++i) { // Step 2 O(n)

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

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

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

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

for (int l = 0; l < n; ++l) { // Step 6 O(n3)

std::cout << arr[j] * arr[k] * arr[l] << std::endl; // Step 7 O(n3).

Thus, the overall time complexity of this code is O(n3).

You might also like