
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Lab; Class: DATA STRUCTURES; Subject: Computer Science; University: Rensselaer Polytechnic Institute; Term: Fall 2006;
Typology: Lab Reports
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Here is a silly pair of mutually-recursive functions:
bool Odd(int number);
bool Even(int number) { if (!Odd(number)) return true; else return false; }
bool Odd(int number) { if (!Even(number)) return true; else return false; }
Type this code into your programming environment and try it out. Use the debugger to see what goes wrong. Rewrite the code, but you are only allowed to use subtraction and testing if something is equal to zero. Also Odd cannot directly call itself and Even cannot directly call itself.
To complete this checkpoint: Show a TA what goes wrong in the original version and how you fixed the problem.
Study the recursive definition below which computes the nth Fibonacci number. Draw the complete acti- vation record hierarchy that results from the function call fib a(4). This recursion example is complex to analyze exactly, but find a reasonable upper bound on the number of calls to fib a as a function of n.
int fib_a(int n) { assert (n >= 0); if (n == 0) return 1; if (n == 1) return 1; return fib_a(n-1) + fib_a(n-2); }
To complete this checkpoint: Show a TA your diagram and analysis.