The question, apparently, is completely off topic, since there is an asymptotic_complex tag ...
According to CLRS , p. 49,
"The number of anonymous functions in an expression is understood to be equal to the number of times an asymptotic notation appears. For example, in an expression
sum (O (i), i = 1..n)
there is only one anonymous function (function i). Thus, this expression does not match O (1) + O (2) + ... + O (n), which really does not have a clear interpretation "
Actually, in your formula the constants that lie behind the note O can be different, and their growth can change the asymptotic behavior of the whole sum. Do not write it!
To answer your question more fully, in the sum (O (i), i = 1..n), you can use the fact that (see GKP , p. 450 for the following)
O (f (n) g (n)) = f (n) O (g (n))
So O (i) = i O (1), this time with the same O (1) in your formula. Hence,
sum (O (i), i = 1..n) = sum (i, i = 1, n) O (1)
= n (n + 1) / 2 O (1) = O (n ^ 2)
Thus, you can easily get rid of your amount.
user1220978
source share