Concept explainers
Ackermann’s Function
Ackermann’s Function is a recursive mathematical
If m = 0 then return n + 1
If n = 0 then return A(m−1, 1)
Otherwise, return A(m−1, A(m, n−1))
Test your function in a driver
A(0, 0) A(0, 1) A(1, 1) A(1, 2) A(1, 3) A(2, 2) A(3, 2)
Want to see the full answer?
Check out a sample textbook solutionChapter 20 Solutions
Starting Out with C++ from Control Structures to Objects Plus MyLab Programming with Pearson eText -- Access Card Package (9th Edition)
Additional Engineering Textbook Solutions
Database Concepts (8th Edition)
Starting Out With Visual Basic (8th Edition)
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
- Ackermann’s Functionarrow_forwardWrite the definition of a recursive function int simpleSqrt(int n) The function returns the integer square root of n, meaning the biggest integer whose square is less than or equal to n. You may assume that the function is always called with a nonnegative value for n. Use the following algorithm: If n is 0 then return 0. Otherwise, call the function recursively with n-1 as the argument to get a number t. Check whether or not t+1 squared is strictly greater than n. Based on that test, return the correct result. For example, a call to simpleSqrt(8) would recursively call simpleSqrt(7) and get back 2 as the answer. Then we would square (2+1) = 3 to get 9. Since 9 is bigger than 8, we know that 3 is too big, so return 2 in this case. On the other hand a call to simpleSqrt(9) would recursively call simpleSqrt(8) and get back 2 as the answer. Again we would square (2+1) = 3 to get back 9. So 3 is the correct return value in this case.arrow_forwardConsider the following recursive function: if b = 0, if 6 > a > 0, a f(b, a) f (b, 2.(a mod b)) otherwise. f(a, b) = Estimate the number of recursive applications required to compute f(a, b).arrow_forward
- Write a recursive function to compute the following series: m(i) = 1/2 + 2/ 3 + . . . + i/i + 1 Write a test program that prompts the user to enter an integer for i and displays m(i).arrow_forwardWrite a recursive function that returns the sum of the digits of an integer.int sumOfDigits(int x);arrow_forwardUse C++ programming Language write a recursive function program that prompts the user to enter the number of lines in the pattern and uses the recursive function to generate the pattern. For example, specifying 4 as the number of lines generates the below pattern: * * * * * * * * * * * * * * * * * * * * * * * * *arrow_forward
- 4. CodeW. X b For fun X Solved x b Answer x+ Ohttps://codeworko... CodeWorkout X264: Recursion Programming Exercise: Multiply For function multiply,write the missing base case condition and action. This function will multiply two numbers x and y.You can assume that both x and y are positive. Examples: multiply(2, 3) -> 6 Your Answer: 1 public int multiply(int x, int y) { 2. if > { > } else { return multiply(x 1, y) + y; 3. 5. { 7. 1:08 AM 50°F Clear 日arrow_forwardDetermine the output of the following recursive function when n = 64. (show your working/steps) int func (int n) { if (n ==1) return 0 else return 2 + func ( ) }arrow_forwardlanguage: Python Problem: Write a recursive function power(x, n), where n is 0 or a postive integer. For example, power(2, 10) will return 1024. Write a suitable base case, and for the general case use the idea that x" = x* x"-1.arrow_forward
- Write a recursive function to compute the following series:arrow_forwardWrite a recursive function that returns true if the digits of a positive integer are in increasing order; otherwise, the function returns false. Also, write a program to test your function.arrow_forwardThe following function f uses recursion:def f(n):if n <= 1return nelse return f(n-1) + f(n-2)Let n be a valid input, i.e., a natural number. Which of the following functions returns the same result but without recursion?a) def f(n):a <- 0b <- 1 if n = 0return aelsif n = 1 return belsefor i in 1..nc <- a + b a <- b b <- c return bb) def f(n):a <- 0i <- n while i > 0 a <- a + i + (i-1) return ac) def f(n): arr[0] <- 0 arr[1] <- 1 if n <= 1return arr[n]elsefor i in 2..n arr[i] <- arr[i-1] + arr[i-2]return arr[n]d) def f(n): arr[0..n] <- [0, ..., n] if n <= 1return arr[n]elsea <- 0 for i in 0..n a <- a + arr[i]return aarrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage