-2

I'm trying to find out the Complexity of the given program. Suppose we have;

int a = θ;
for (i=θ; i<n; i++){
for(j = n; j>i; j--)
{
a = a + i + j;
}
}
Zum Zum
  • 1
  • 1
  • 2
  • 6
    Possible duplicate of [How to find time complexity of an algorithm](https://stackoverflow.com/questions/11032015/how-to-find-time-complexity-of-an-algorithm) – HMD Jan 02 '19 at 16:18

1 Answers1

0

Complexity: O(N*N)

Explanation: The code runs total no of times

`= N + (N – 1) + (N – 2) + … 1 + 0

= N * (N + 1) / 2

= 1/2 * N^2 + 1/2 * N

O(N^2) times`