Easy: Solve T(n)=T(n-1)+n by Iteration Method

前端 未结 5 2231
灰色年华
灰色年华 2021-02-19 19:59

Can someone please help me with this ?

Use iteration method to solve it. T(n) = T(n-1) +n

Explanation of steps

5条回答
  •  天涯浪人
    2021-02-19 20:37

    Expand it!

    T(n) = T(n-1) + n = T(n-2) + (n-1) + n = T(n-3) + (n-2) + (n-1) + n
    

    and so on, until

    T(n) = 1 + 2 + ... + n = n(n+1)/2   [= O(n^2)]
    

    provided that T(1) = 1

提交回复
热议问题