I'm studying algorithms and I've met a problem, that I can't solve.
for(int i = 0; i < n; i++)
for( int j = 0; j < i; j++)
sum++;
So, time complexity of this code is n^2. But. First loop is iterating n times and I understand that. But second one is iterating n(n+1)/2. So.. It becomes n*(n(n+1))/2. Where I went wrong?