Results 1 to 3 of 3
- 12-28-2009, 05:41 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 14
- Rep Power
- 0
recursion and tail-recursion differences
hello,
i need some tuning about this issue,
what is the difference in the structure of the recursions when the final result is computed?
what is the difference in the nature of the “base case” (the case that is handled within the stop condition of the recursion).
maybe some other differences you can think of...
thanks,
OPLast edited by OptimusPrime; 12-30-2009 at 07:47 AM.
- 12-28-2009, 05:57 PM #2
the final result usually returns a value whereas the other results return another function call. The base case is used to tell the recursive call when to stop calling itself or else you'll end up in a stack overflow and your loop will never end.
Liberty has never come from the government.
Liberty has always come from the subjects of government.
The history of liberty is the history of resistance.
The history of liberty is a history of the limitation of governmental power, not the increase of it.
- 12-28-2009, 06:26 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
One (theoretical) important aspect is: if the size of a problem is 'n' (n characters in a String, n nodes in a tree etc.) and a recursive solution needs a stack of size O(n) an iterative solution will be better; so e.g. reversing a String or calculating the n-th Fibonacci number is better done iteratively than recursively. On the other hand traversing a (binary) tree just needs O(log(n)) slots on a stack so it can be better done recursively.
kind regards.
Jos
Similar Threads
-
Recursion
By kathyla18 in forum New To JavaReplies: 2Last Post: 04-09-2009, 02:26 AM -
Recursion
By jachandru in forum New To JavaReplies: 1Last Post: 01-24-2009, 12:52 PM -
Recursion
By Mika in forum New To JavaReplies: 5Last Post: 01-04-2009, 01:13 AM -
Recursion help
By rjg_2186 in forum New To JavaReplies: 1Last Post: 01-02-2009, 08:03 AM -
Help With Recursion
By andrew777 in forum New To JavaReplies: 1Last Post: 03-29-2008, 12:51 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks