Well, thats what I get for not taking the next step.
Each row is an arithmetic sequence. There is a formula for calculating the sum of an arithmetic sequence

Which means an O(N) algorithm would be
Code
SUM = 0
D = 1 //difference between each cell is 1
FOR A = 1 to N
SUM += SEQUENCE(A,D,N)
END
But you can go a little further than that. Because the sum of every arithmetic sequence IS an arithmetic sequence. Every row you are adding N to the previous row's sum.
F(N) = (N/2) (2A + (N - 1)D)
D = N, A = G(N)
F(N) = (N/2) (2G(N) + (N - 1) N)
= (N/2) (2G(N) + N^2 - N)
G(N) = (N/2) (2A + (N - 1)D)
D = 1, A = 1
G(N) = (N/2) (2(1) + (N - 1) (1))
= (N/2) (2 + N - 1)
= (N/2) (N + 1)
= (N^2 + N) / 2
Subsitituting
F(N) = (N/2) ( 2 ( ( N^2 + N )/2) + N^2 - N)
= (N/2) (N^2 + N + N^2 - N)
= (N/2) (2N^2)
= 2N^3 / 2
= N^3
F(N) = N^3
So, time complexity for this function would be constant at O(1).
Interesting math problem. Boring algorithm. For a Data Structure and Algorithm course, the cool part is developing an algorithm to solving the problem. When the problem can be reduced to constant time, yea the math may be interesting, but it loses its luster. This is almost like a trick question from the professor.
This post was edited by Minkomonster on Feb 7 2014 12:18am