Can someone explain how Big-Oh works with Summations?

前端 未结 5 1042
轻奢々
轻奢々 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:34

    The simplest approach that jumps out to me is a proof by induction.

    For the first one, essentially you need to show that

    sum (i=1 to n) i^2 < k*n^3, k > 2,n > 0
    

    If we use the generalized principle of induction and take a base case of n=1 and k=2.

    we get 1<2*1.

    Now of course take the inductive hypothesis, then we know that

    sum(i=1 to n) i^2, with a bit of fun math we get to

    sum(i=1 to n) i^2+(n+1)^2 < k *n^3+(n+1)^2.

    • Now show k * n^3+(n+1)^2 < k *(n+1)^3

    • k *n^3+n^2+2n+1 < k *n^3+k *(3n^2+3n+1)

    • k *n^3 < k *n^3+(3k-1) *n^2+(3k-2) *n+k-1

    Therefore, our original result is correct.

    For the second proof you need to show that sum(i=1 to n) log_2(i) >= k*n*log(n), which I'll leave as an exercise for the reader ;).

    The main step though is sum(i=1 to n) log_2(i)+log_2(n+1)>=k*n*log(n)+k*log(n+1), for some k, so clearly k is 1.

提交回复
热议问题