

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!


CSE 232 Spring, 2009 Name: __________________________________
Lab Exercise #14 -- Recursive Functions
Copy all of the files named "~cse232/Labs/lab14.*" into your account, then perform the following experiments.
Back2 <-- 1 Back1 <-- 3 loop from 3 to N Result <-- Back1 + Back Back2 <-- Back Back1 <-- Result endloop
Test your completed program to be sure that both implementations for computing the Lucas numbers are correct.
cout << "+++ Entering N: " << N << " Count: " << Count << endl;
cout << "--- Exiting N: " << N << " *** Result: " << Result << endl;
Then, use the program to recursively compute f(6). In the space below, draw a "call graph" (similar to the one on page 529 of the Nyhoff textbook) for f(6). Be sure to label each branch in the call graph to indicate temporal order ("A" for the first call, "B" for the second call, etc).
f( m, n ) = n+1 if m = 0 f( m, n ) = f( m-1, 1 ) if n = 0 f( m, n ) = f( m-1, f( m, n-1 ) ) otherwise
The program should count and display the number of function calls that are required to compute a specified function value.
Warning: even for small argument values, Ackermann’s function requires many recursive function calls.