Reputation: 83
int sum = 0;
for (int i = 1; i < n; i *= 2) {
for (int j = n; j > 0; j /= 2) {
for (int k = j; k < n; k += 2) {
sum += i + j * k;
}
}
}
I am trying to calculate the operation count of the above given nested loop. The first and second loop variable is independent.
My try:
10n(logn)^2 + 1
How do I calculate it correctly? The most inner loop is the main problem.
Upvotes: 0
Views: 433
Reputation: 2977
Methodically, you may proceed using Sigma notation:
Upvotes: 1