Campbell Ritchie wrote:Question maybe a bit scary for the “beginning” forum, so I think I shall move you.
You wouldn't pass “Array[]” to a method, but “Array”. Once you work that out, yes the whole code runs in quadratic complexity (=n²) as its upper limit. It might behave more like linear if the size of the array is very small, but complexity is calculated on a worst‑case basis, so it is correct ot say quadratic.
So in that case, if you had 3 for loops nested, the complexity would be N cubed.
But what if you had 4 For loops in total, a nested loop at the beginning of the program and a different nested for loop at the end of the program.
Would the complexity still be N squared ? Or N^4 now ?