sum = 0;
for (int i = 0; i < N; i++)
for (int j = i; j ≥ 0; j--)
sum++;
I found out the big-oh to be O(n^2) but I am not sure how to find the theta bound for it. Can someone help?
sum = 0;
for (int i = 0; i < N; i++)
for (int j = i; j ≥ 0; j--)
sum++;
I found out the big-oh to be O(n^2) but I am not sure how to find the theta bound for it. Can someone help?
You can make use of sigma notation to derive asymptotic bounds for your algorithm:
Since we can show that T(n) O(n^2) (upper asymptotic bound) as well as in Ω(n^2) (lower asymptotic bound), it follows that T(n) is in Θ(n^2) ("sandwiched", upper and lower asymptotic bound).
In case it's unclear: note that the inner and out sums in the initial expressions above describe your inner and outer for loops, respectively.