


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



2
Recursive functions are characterized by:
4
() 2 ( 1 ) 1 ( 0 ) 1 = "! + = Sn S n S ... ( 3 ) 15 ( 2 ) 7 ( 1 ) 3 ( 0 ) 1 = = = = S S S
Recursively defined functions contain “self-referential” expressions. Closed forms are formulae that require no recursive calls
7 Infinite Recursion — Prog 1801
Stack overflow occurs when a program runs out of space to keep track of method calls. 8 Counting Stack Depth — Prog 1802
9 Stack Overflow
Your Mileage May Vary. Run Prog 1802 on your computer system & note how far you get before observing a StackOverFlow error. 10 For each invocation of f
Hand-Tracing
a( 3 , 5 ) 1 + a( 2 , 5 ) 1 + 1 + a( 1 , 5 ) 1 + 1 + 1 + a( 0 , 5 ) 1 + 1 + 1 + 5 1 + 1 + 6 1 + 7 The recursion 8 “bottoms out” at the call a(0,5) What does method a compute? sumInts
sumInts( 3 ) + 4 (sumInts( 2 ) + 3 ) + 4 ((sumInts( 1 ) + 2 ) + 3 ) + 4 (((sumInts( 0 ) + 1 ) + 2 ) + 3 ) + 4 ((( 0 + 1 ) + 2 ) + 3 ) + 4
Recursion in the Past
Recursion in the Present