Fall 2024 - CS502 - 1 - BC240205841
Fall 2024 - CS502 - 1 - BC240205841
Algorithms
Assignment #1 Fall-
2024
Nayyab Asghar
BC240205841
Question #1:
Consider the following piece of code of a
function that processes a list of integers in the
following way:
Int n = arr.size); // Step 1
/ First loop: print each element of the array for
(int I = 0; I <n; ++i){ // Step 2 std::cout <<
arr[i] << std::endl; // Step 3
/ Second nested loops: print the product of
each triplet of elements for (intj = 0;j <n; ++j)
{ // Step4 for (int k =0; k<n; ++k) { // Step 5
for (int l = 0;l<n; ++1){ // Step 6
Std::cout << arri]* arr[k]* arr1] <<
std::endl; // Step 7
You have to determine the time complexity of
the given C++ code by analysing each line of
the code and also determine the overall time
complexity of this code. You are required to
show all steps in detail.
Solution #1: