Big O from Code

It is often easy to determine Big O directly from code:


for ( i = 0; i < n; i++ )
  for ( j = 0; j < n; j++ )
    sum += a[i][j];

We all know this is O(n2); but what about:


for ( i = 0; i < n; i++ )
  for ( j = 0; j <= i; j++ )
    sum += a[i][j];

Contents    Page-10    Prev    Next    Page+10    Index