Question: Please write down the code in JAVA. Objectives .To gain experience with using recursion by implementing the Ackermann's Function. To gain experience with using class



Please write down the code in JAVA.
Objectives .To gain experience with using recursion by implementing the Ackermann's Function. To gain experience with using class variables to record method invocation history Description The Ackermann's function is of interest because it grows rapidly with respect to the size of m and n. It is the simplest example of a well-defined total function which is computable but not primitive recursive. This means it cannot be implemented using only for-loops. Notice that for- loops (which have a fixed iteration limit) are a special case of while-loops. The Ackermann's function is defined recursively for nonnegative integers as follows 2+1 Acker (m-1, 1) Acker (m -1. Acker (m, n-1) if m=0 if n=0 otherwise Acker (m, n)- Implement the function as a method in Java and trace the histrory of method invocations as follows (e.g., m-1, n-2): Input two intergers separated by a space character (enter "q to quit): 1 2 Enter method acker: m = 1, n = 2 Enter method acker: m = 1, n = 1 Enter method acker: m- 1, n = 0 Enter method acker: m 0, n 1 Leave method acker: acker (0, 1)2 Leave method acker: acker (1, 0) = 2 Enter method acker: m = 0, n = 2 Leave method acker: acker (0, 2) = 3 Leave method acker: acker (1, 1) = 3 Enter method acker: m = 0, n = 3 Leave method acker: acker (0, 3) = 4 Leave method acker acker (1, 2) 4 Total number of invocations = 6, result 4
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
