What counts as space
Time counts steps; space counts memory. The list a = [4, 1, 5, 2] is the input, n = 4 numbers. It is in memory before any call, so we count only the extra memory a function makes: its auxiliary space.
The call stack
Call rsum(a). Python gives every running call a frame: a small block of memory for its local names, here a and i. Frames stack up on the call stack. One call running means one frame.
Line 4 cannot add a[i] until rsum(a, i + 1) answers. So the frame for i = 0 waits, and a new frame goes on top for i = 1, then 2, then 3. Every waiting call keeps its frame.
At i = 4, i == len(a), so this call returns 0 without calling again. Right now 5 frames are in memory at once, one for each i from 0 to 4. That is n + 1, the highest the stack gets.
Now each call finishes and its frame is freed. i = 3 returns 2 + 0 = 2, i = 2 returns 5 + 2 = 7, then 8, then 12. The stack shrinks to nothing, but the peak ring stays at 5.
Proving the cost
Auxiliary space is the most extra memory in use at once, not the total ever used. rsum peaks at n + 1 frames, each a fixed size, so its auxiliary space is Θ(n). With no depth limit, a million numbers need a million frames.
lsum adds the same list with a loop. The counters now track lsum: one call, one frame, holding total and x. They are overwritten each pass, so memory stays the same for any n: auxiliary space Θ(1). Both take Θ(n) time.
Deep stacks are a real limit. CPython allows 1000 nested calls by default (see sys.getrecursionlimit()) and then raises RecursionError. So rsum fails on a list of 2,000 numbers, while lsum adds a million without trouble.
What happens
;; step 1/8 · extra-space
a = [4, 1, 5, 2] n = 4
total space = input + auxiliary
auxiliary space = extra memory the function
uses while it runs
the input is the same for every algorithm,
so space cost counts only the auxiliary part
Cost model: one frame counts as one unit of memory. The byte size of a real frame depends on the Python version, but it is the same for every call of rsum, so counting frames gives the right growth rate. Freed memory is used again by the next call, so space is measured at the busiest moment. For a recursive function that is the depth of the deepest chain of waiting calls.