# CS1121605b - Computer Science Foundation Exam Computer...

This preview shows pages 1–3. Sign up to view the full content.

Computer Science Foundation Exam December 16, 2005 Computer Science Section 1B No Calculators! Name: SSN: KEY Solutions and Grading Criteria Sco 50 re: In this section of the exam, there are four (4) problems. You must do all of them. The weight of each problem in this section is indicated with the problem. Partial credit cannot be given unless all work is shown and is readable. Be complete, yet concise, and above all be neat .

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
1. [16 points – 10 points part (a), 6 points part (b)] Ackermann’s function grows faster than any primitive function. It is defined below. (a) Construct a recursive function that will correctly produce the Ackermann number for values of m and n . (b) Trace the execution of your function for the values m = 1 and n = 5 and determine the value produced by the function. 0 , )) 1 , ( , 1 ( ) , ( 0 ) 1 , 1 ( ) 0 , ( 0 1 ) , 0 ( = > = + = n m for n m A m A n m A m for m A m A n for n n A (a) One possible solution is: #include <stdio.h> int A(int a, int b); int main (void) { int a = 1; int b = 5; int result; result = A(a,b); printf("\n%s%d\n","A[1,5] returns: ", result); return 0; } int A(int m, int n) { if ((m == 0) && (n >= 0)) { return(n+1); } else if ((m > 0) && (n == 0)) { return(A(m-1,1)); } else if ((m >= 0) && (n >= 0)) { return(A(m-1, A(m, n-1))); } } There is certainly more than one way to solve
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 6

CS1121605b - Computer Science Foundation Exam Computer...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online