Can someone explain how Big-Oh works with Summations?

前端 未结 5 1083
轻奢々
轻奢々 2021-01-11 22:54

I know this isn\'t strictly a programming question, but it is a computer science question so I\'m hoping someone can help me.

I\'ve been working on my Algor

5条回答
  •  无人及你
    2021-01-11 23:32

    Probably, your CPU will multiply 32-bit integers in constant time. But big-Oh doesn't care about "less than four billion", so maybe you have to look at multiplication algorithms?

    According to Wolfram, the "traditional" multiplication algorithm is O(n2). Although n in this case is the number of digits, and thus really log(n) in the actual number. So I should be able to square the integers 1..n in time O(n.log(n)). Summing is O(log(n2)), which is obviously O(log(n)), for an overall complexity of O(n.log(n)).

    So I can quite understand your confusion.

提交回复
热议问题