Recursive functions use something called “the call stack.” When a program calls a function, that function goes on top of the call stack. This similar to a stack of books. You add things one at a time.
Does recursion use stack or heap?
Trampolining makes recursive functions stack safe but not heap safe, as each new object to build the data structure is allocated on the heap. Consequently, if the function recurses too often, an OutOfMemoryError will occur at some point.
How stacks are used in implementing recursion?
The most fundamental use of stacks relates to how functions are called. One function can call another function which can call a third and so on to any depth until there is no more stack left to support further calls.