© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
16 replies
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
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!
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

miniMax algorithm
C#CC# / help
4y ago
Exception Signing Algorithm
C#CC# / help
2y ago
simple algorithm question
C#CC# / help
2y ago
✅ Specific Sorting Algorithm
C#CC# / help
3y ago