Counting the call stack in interview space complexity

← Back to Blog & Articles

Space complexity follows the same growth-rate logic as time complexity, but measures memory instead of operations, and candidates consistently forget one major contributor: the call stack used by recursion.

Every active recursive call consumes a stack frame — space to hold that call’s local variables and its return address — and that frame stays allocated for as long as the call (and everything it calls) hasn’t yet returned. A recursive function with a single chain of depth n, like the naive linear recursion described earlier, uses O(n) auxiliary space for the call stack alone, even if it doesn’t allocate a single explicit data structure — a fact that surprises candidates who mentally credit recursive solutions with “no extra space” just because they don’t see an array or a hash map anywhere in the code. A recursive function that halves its input at each step, by contrast, only ever has O(log n) frames alive at once, because the chain of nested calls is only O(log n) deep even though the total number of calls across the whole tree might be larger (in a branching recursion, total calls and maximum simultaneous depth are different quantities, and it’s depth — not the total call count — that determines stack space). When you state the space complexity of a recursive solution in an interview, always account for the call stack explicitly, and say so out loud; it’s an easy, high-signal detail to include and an easy one to be caught skipping.

Continue with the book

Explore the full treatment, worked examples, and exercises in Algorithmic Edge.


Companion article for Algorithmic Edge, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.

Scroll to Top