To have a big-O which is proportional to the solution it should reduce to 1 i.e. it should make as many calls as the answer.
For there to be O(2^n) time complexity
public static int power(int base, int n) {
return n == 0 ? 1 : multiply(base, power(base, n -1);
}
public static int multiply(int a, int b) {
return a > 0 ? add(multiply(a - 1, b), b) : 0;
}
public static int add(int a, int b) {
return a > b ? 1 + add(a -1, b) : b > 0 ? 1 + add(0, b -1) : 0;
}
To calculate 2^n it will reduce down to 1 +
2^n times.