Complexity of the recursion: T(n) = T(n-1) + T(n-2) + C

前端 未结 5 1541
北恋
北恋 2021-01-12 11:12

I want to understand how to arrive at the complexity of the below recurrence relation.

T(n) = T(n-1) + T(n-2) + C Given T(1) = C and

5条回答
  •  悲&欢浪女
    2021-01-12 12:09

    The complexity is related to input-size, where each call produce a binary-tree of calls

    Where T(n) make 2n calls in total ..

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

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

    O(2n)

    In the same fashion, you can generalize your recursive function, as a Fibonacci number

    T(n) = F(n) + ( C * 2n)

    Next you can use a direct formula instead of recursive way

    Using a complex method known as Binet's Formula

提交回复
热议问题