How to solve: T(n) = T(n - 1) + n

前端 未结 4 639
慢半拍i
慢半拍i 2020-12-03 22:00

I have the following worked out:

T(n) = T(n - 1) + n = O(n^2)

Now when I work this out I find that the bound is very loose. Have I done so

4条回答
  •  情书的邮戳
    2020-12-03 22:41

    Looks about right, but will depend on the base case T(1). Assuming you will do n steps to get T(n) to T(0) and each time the n term is anywhere between 0 and n for an average of n/2 so n * n/2 = (n^2)/2 = O(n^2).

提交回复
热议问题