I have a function f(x) that calls f(x / 2) if x is even and calls both f((x + 1) / 2) and f((x - 1) / 2) if x is odd. Note that f(1) = constant and we don't recurse further than f(1). (So, it can be said that f(1) is the base condition.)
If I memoize f(x), what will be the time complexity of computing f(x)? Will it be O(2 ^ n) because two functions are called at every level, or will it improve because of memoization?
I tried some cases by hand, and it seems that the complexity is no more than O(log n) and only two new functions are called at every level of recursion. (If I don't memoize, it does seem to be O(2 ^ n))
I'd be glad if someone could help me with the complexity. Thanks!