Suppose I have a recursive algorithm that splits input into 2 inputs of size n-1 and solves them recursively. It combines the results in a constant time say c.
So formulating an equation for this,
T(n) = 2T(n-1) + c
In order to find the complexity of this one, I used the recursive tree method. Since input is divided into 2 at each step, the number of nodes will get squared at each step while since only one element is getting eliminated, every level will lose only one element from the list.
So I think that the complexity of this problem should be Θ(n2)
Am I right in this thought process. If not, What am I doing wrong?
Thank you.
The number of nodes at each step doesn’t get squared. Instead, it doubles at every level. For example, the number of nodes at
As a result, the total number of nodes in your recursion tree will be 1 + 2 + 4 + 8 + … + 2n = 2n+1 – 1. Accordingly, the work done will be c2n+1 – c, which is Θ(2n). This is exponential time, rather than quadratic time.
Hope this helps!