r/learnjava • u/[deleted] • Jan 18 '20
Why is the big o n^(2)
Sum of numbers from 1 +2 + 3... N
1
Upvotes
0
Jan 18 '20
[deleted]
1
Jan 18 '20 edited Jan 18 '20
my teacher said its n2 and im not understanding
she said its (1+2+3... +N) * N
and thats why its n2
0
u/desrtfx Jan 18 '20
The formula you wrote in this comment is not the sum of the natural numbers and even with the * N it is still O(n).
A single multiplication does not change the algorithmic complexity.
1
1
u/Philboyd_Studge Jan 18 '20
It can be done in O(1) if you're clever ;)