CS502 Assignment 1 Solution
CS502 Assignment 1 Solution
Question No. 1
Consider the following piece of code of a function that processes a list of integers in the followin
g way:
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 st
eps in detail.
Answer:
int n = arr.size(); // Step 1
Answer:
Time Complexity: This step involves fetching the size of the array, which is an O(1)
operation. Therefore, the time complexity for Step 1 is O(1).
Answer:
When we have different terms in the time complexity, we consider the term wit
h the highest order of growth. In this case, O(n³) dominates the others for large
values of n.