Recursion to Iteration
A tail call is a loop in disguise: replace the call with an update of the arguments and jump back.
The Call Stack: Tail recursion reuses the frame
factTail(5, 1) calls factTail(4, 1 x 5 = 5) and has nothing to do with the result but pass it on. The frame is reused: same slot, new arguments.
Cost
- Space
- O(depth)
Before this
Related
Taught by the same lesson
The Call Stack covers these too, in the same run.