'complexity - why is this code's complexity O(n²)?
i=0
j=0
while j<n:
t[j*n+i] =i
if i = n-1:
j+=1
i= 0
else:
i += 1
Can you explain to me why this code's complexity is O(n2)?
Solution 1:[1]
Well, first you are using while. Then you are traversing over an array. Each of them is n, since they're combined it gives us square, as explained briefly.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ihatec |
