Can not figure out complexity of this recurrence

前端 未结 4 690
借酒劲吻你
借酒劲吻你 2021-01-21 07:21

I am refreshing on Master Theorem a bit and I am trying to figure out the running time of an algorithm that solves a problem of size n by recursively solving 2 subp

4条回答
  •  礼貌的吻别
    2021-01-21 07:23

    Don't even think about Master's Theorem. You can only use Masther's Theorem when you're given master's theorem when b > 1 from the general form T(n) = aT(n/b) + f(n).

    Instead, think of it this way. You have a recursive call that decrements the size of input, n, by 1 at each recursive call. And at each recursive call, the cost is constant O(1). The input size will decrement until it reaches 1. Then you add up all the costs that you used to make the recursive calls. How many are they? n. So this would take O(2^n).

提交回复
热议问题