← BYTES
Algorithms·Starter·Ref: 12.1.9
Why can deep, unbounded recursion cause a program to crash with a stack overflow?
Have a question about this video? Mention reference 12.1.9 when you contact us.
a.Recursive functions cannot use local variables
b.Recursion always runs out of CPU time before memory
c.Each recursive call adds a new frame to the call stack, and the stack has a fixed, finite size
d.Stack overflow only happens with sorting algorithms
Every function call -- recursive or not -- pushes a new stack frame holding local variables and the return address; recursion that never reaches its base case (or recurses too deeply even with one) keeps pushing frames until the fixed-size call stack is exhausted, crashing the program.
Find this on YouTube & Instagram
Every BYTES video is tagged with its reference number and topic — search any of these on YouTube or Instagram to find this one:
#BYTES#BYTES1219#Algorithms