Wednesday, January 5, 2011

StackOverflowError

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.
http://download.oracle.com/javase/1.4.2/docs/api/java/lang/StackOverflowError.html


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.
http://www-2.cs.cmu.edu/~cburch/pgss97/slides/0716-recurse.html



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

No comments:

Post a Comment