C#C
C#3y ago
moshimoshi

✅ Algorithm analysis

Can someone help me understand how we got this formula to calculate time efficiency from this code?

sum = 0
loop i from 1 to n
  loop j from 1 to i 
  sum = sum + 1


this is the formula: f(n) = n2/2 + n/2, which is O(n2)

The formula goes like this, 1 + 2 + 3 + 4 + ... + N but i have no idea how to connect the dots. Thanks!
Was this page helpful?