A useful way to solve this type of problem is to think of a recursion tree . Two functions of a recursive function for identification:
- Tree depth (how many total return statements will be executed before the base case)
- Tree width (how many total recursive function calls will be made )
T(n) = 2T(n-1). , O(2^n), .
C
/ \
/ \
T(n-1) T(n-1)
C
____/ \____
/ \
C C
/ \ / \
/ \ / \
T(n-2) T(n-2) T(n-2) T(n-2)
, .
n 1. , n, . 2 n , 2^n, O(2^n).
, . , O(recursion depth). , n , , , O(n).