Professional Documents
Culture Documents
Quiz 1 TC - Solution
Quiz 1 TC - Solution
Q#1: Find the Time complexity T(n) and Big-O of the following piece of code and show all working.
int sum = 0;
for (int i = 4; i < n; i++) {
for (int j = i-3, sum = a[i-4]; j <= i; j++)
sum += a[j];
cout<<”Sum=”<<sum<<end1;
}
Statements Cost Frequency Cost* Frequency
int sum = 4; 1 1 1
int i = 4; 1 1 1
i < n 1 n-4 +1 n-3
i++ 2 n-4 2n-8
O(N)