This preview shows pages 1–5. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: This can lead to simple, elegant code. • However, recursive solutions entail a cost in time and memory : each recursive call requires that the current process state (variables, program counter) be pushed onto the system stack, and popped once the recursion unwinds. • This typically affects the running time constants , but not the asymptotic time complexity (e.g., O(n), O(n 2 ) etc.) • Thus recursive solutions may still be preferred unless there are very strict time/memory constraints. Last Updated 120124 10:12 AM CSE 2011 Prof. J. Elder  45  The “Curse” in Recursion: Errors to Avoid // recursive factorial function public static int recursiveFactorial( int n) { return n * recursiveFactorial ( n 1 ); } • There must be a base condition: the recursion must ground out!...
View
Full
Document
This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.
 Fall '11
 Elder
 Data Structures, Recursion

Click to edit the document details