+ 8
What is the complexity of this code?
void conundrum (int n) { int i, j, k; int r = 0; for(i=1; i<=n; i++) for (j = i+1; j<= n; j++) for (k=i+j-1; k<= n; k++) r = r+1; }
5 ответов
+ 9
thank u @Ran 😊
+ 9
Exactly!
+ 8
Worst case scenario : O(n³)
+ 7
You're welcome!
+ 5
The time complexity of a code is roughly N to the power of the maximum number of nested for loops.
Here it is 3, so O(N³)