What is the time complexity of this algorithm? In my class my teacher calculated the time complexity for this algorithm, relative to the number of sum operations executed: 



She represented the cost of the algorithm  by the following sum:

$\sum\limits_{i=1}^n \sum\limits_{j=1}^i\sum\limits_{k=1}^j 3 = \frac{n^3}{2} + \frac{3n^2}{2} + n $

The step by step used to solve the sum bellow:


n = 10
count=0
for i in range (0, n):
    for j in range (0, i):
        for k in range (0, j):
            count+=3

print count


Then, I wrote a algorithm in python to verify the solution, but it not produce the expected output, for example, for n = 10 we expected 660 operations, but it print 360.

Change the index to start with 1 like in the bellow didn't worked either, in fact it got more distance from the expected (252).

n = 10
count=0
for i in range (1, n):
    for j in range (1, i):
        for k in range (1, j):
            count+=3

print count
In Python, range(0,n) iterates through the values 0, 1, 2, .., n-1 (but not n).  Therefore, your summation should have been

$$\sum_{i=0}^{n-1} \cdots$$

rather than

$$\sum_{i=1}^{n} \cdots$$

and similarly for the other sums as well.