Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Tail Recursion

Name: Anonymous 2011-10-19 21:09

How do i make this function tail recursive in java


public int fib(int n)
{
  return( n <= 1 ? n : fib(n-1) + fib(n-2) );
}

Name: Anonymous 2011-10-19 23:57

>>8

One could implement tail call optimization so that the stack trace still retains information about the where the tail calls where, but it will eventually consume all memory if there is an indefinite amount of tail calls, and the stack trace would likely be unreadable, due to how large it was, even if steps were taken to compress it visually. It would be less of a stack trace, and more of a complete print out of the entire execution of your program from the moment it started.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List