When an algorithm doesn't use more than a constant amount of auxiliary memory but does have O(log(N))
recursive calls (each one taking some extra space on the stack), is that algorithm's space complexity O(1)
or O(log(N))
?
If the recursive algorithm is not exploiting tail recursion, then, yes, a straightforward implementation would be using O(log(N)) space. This is because the runtime must keep O(log(N)) stack frames, each of O(1) size, in memory at once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With