0% found this document useful (0 votes)
55 views2 pages

Fall 2024 - CS502 - 1

Assignment solution

Uploaded by

nayyabasghar13
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)
55 views2 pages

Fall 2024 - CS502 - 1

Assignment solution

Uploaded by

nayyabasghar13
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/ 2

Assignment No.

01
Fall 2024 Total Marks: 20
CS502- Fundamentals of Algorithms

Due Date: 07-Nov-2024

Instructions

Please read the following instructions carefully before solving & submitting assignment:

It should be clear that your assignment will not get any credit (zero marks) if:
 The assignment is submitted after due date.
 The submitted assignment is other than MS Word file.
 The submitted assignment does NOT open or file is corrupted.
 The assignment is copied (from other student or ditto copy from handouts or internet).

Uploading instructions

 For clarity and simplicity, you are required to upload/submit only one .doc/docx file.

Lectures:

 Lectures 1 to 8 are covered in this assignment.

Objectives

 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.

For any query about the assignment, contact at [email protected]


Question No. 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 (int j = 0; j < n; ++j) { // Step 4
for (int k = 0; k < n; ++k) { // Step 5
for (int l = 0; l < n; ++l) { // Step 6
std::cout << arr[j] * arr[k] * arr[l] << 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 det
ermine the overall time complexity of this code. You are required to show all steps in detail.

Good Luck!
Total Marks: 20

You might also like