A million frames
transcript
A function calls itself once for each reading. You have a million readings. Each pending call keeps a frame. How much memory is that?
One frame for each reading, and one for the end. That is a million and one frames alive. At a hundred bytes each, that is a hundred megabytes. All of it before the first answer returns.
Python allows a thousand nested calls by default. On one laptop, nine hundred ninety eight items worked. A thousand items raised a recursion error. The data was small. The stack was the wall.
Now call the function on half the items. A thousand items need only ten frames. A million items need only twenty frames. Halving grows like log n, not like n.
Each pending call is memory. One fewer item each call needs n plus one frames. Half the items each call needs about log n.
A recursion is memory too. Full breakdown in the lecture.