Ackermann\'s function is defined recursively for two non-negative integers M and
ID: 3732295 • Letter: A
Question
Ackermann's function is defined recursively for two non-negative integers M and N as follows: Ackermann(M,N) N + 1 ifM =0 else if N 0 then Ackermann(M -1, 1) else Ack M - 1, Ackermann(M,N 1) February 19, Monday version of this function. 2) On a piece of paper compute by hand the values of Ackermann for Ack(0,0), Ack(0,1), Ack(0,2), Ack(1,0), Ack(1,1), Ack(1,2), Ack(2,0), Ack(2,1), and Ack(2,2) 3) Display a trace of the intermediate values for M and N for Ackermann function when M-2, N -2, and for M- 3, N-2. A trace of Ackermann's function for M 3. N 2, requires about 541 calls to the method. The functional value is 29. A trace of M 2, and N 2, requires about 27 function calls and has a value of 7 February 28, Wednesday: 1) Devise a table look-up method that shortens the process of computing the function values by storing intermediate results for Display the number of "hits to the table look-up when doing Ackermann and using these values when they are available. the table look-up method. March 7, Wednesday 2) Create a of the values of Ackermann's function as the function is being run. On my website are two graphics programs that can be modified to display the values of the Ackermann function. StudentGraphicExample.java reads M and N from the keyboard and is easier to understand. StudentExampleActionListener is fancier. In both programs you must add a method that computes a value for Ackermann's function. The intermediate values of Ackermann are to be graphed using a vertical line for each intermediate value. The graphic screen can be thought of as a two dimensional array of pixels. The pikel(0, 0)Explanation / Answer
We will have 2-D array ack for say M = 3 and N = 2
We will manually fill this 2-d array by calculating Ackerman(i,j)
Once this array is present , we can write the Ackerman function as follows:
for m = 3 and n = 2
int Ackerman(int m, int n){
if (m == 0)
return n+1;
else{
if (n == 0){
return lookup(m-1,1)
}
else{
return lookup(m-1, lookup(m,n-1));
}
}
}
int lookup(int m, int n){
return ack[m][n];
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.