Warm tip: This article is reproduced from serverfault.com, please click

Big O, what is the complexity of summing a series of n numbers?

发布于 2012-02-12 21:34:21

I always thought the complexity of:

1 + 2 + 3 + ... + n is O(n), and summing two n by n matrices would be O(n^2).

But today I read from a textbook, "by the formula for the sum of the first n integers, this is n(n+1)/2" and then thus: (1/2)n^2 + (1/2)n, and thus O(n^2).

What am I missing here?

Questioner
user1032613
Viewed
0
svick 2012-02-13 05:47:22

The big O notation can be used to determine the growth rate of any function.

In this case, it seems the book is not talking about the time complexity of computing the value, but about the value itself. And n(n+1)/2 is O(n^2).