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

后端 未结 10 743
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 01:16

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 textbo

10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-14 01:50

    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).

提交回复
热议问题