Wednesday, January 5, 2011


Since JDK1.0, there is such a error (extended from java.lang.VirtualMachineError), thrown when a stack overflow occurs because an application recurses too deeply. This is the java doc from Sun (now part of Oracle). Therefore, usually StackOverflowError results from too deep nest calls, or recursive calls. It might be direct recursive or indirectly recursive.

Recursion is when a function calls itself.
Tail Recursion: A call is tail-recursive if nothing has to be done after the call returns. I.e. when the call returns, the returned value is immediately returned from the calling function. More simply, tail recursion is when the recursive call is the last statement in the function.
Head Recursion: A call is head-recursive when the first statement of the function is the recursive call.

Efficiency of Recursion?
Tail Recursion v.s. Iteration?

No comments:

Post a Comment