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 (9th Edition)
Additional Engineering Textbook Solutions
Database Concepts (7th Edition)
Software Engineering (10th Edition)
Introduction to Programming Using Visual Basic (10th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
Starting Out with Python (4th Edition)
Starting Out with C++: Early Objects (9th Edition)
- 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_forwardCodeW For fun X C Solved https://codeworkou... 臺亂 CodeWorkout X272: Recursion Programming Exercise: Is Reverse For function isReverse, write the two missing base case conditions. Given two strings, this function returns true if the two strings are identical, but are in reverse order. Otherwise it returns false. For example, if the inputs are "tac" and "cat", then the function should return true. Examples: isReverse("tac", "cat") -> true Your Answer: 1 public boolean isReverse(String s1, String s2) { 2. if > 3. 4. else if > return true; return false; 5. 6. else { String s1first = String s2last return s1first.equals (s2last) && 51. substring(0, 1); s2, substring(s2.length() 1); 7. 8. 6. isReverse(s1.substring(1), s2.substring(0, s2.length() 1)); { 12} 1:11AM 50°F Clear 12/4/2021arrow_forward
- Consider 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_forwardCodeW X b For func x C Solved X b Answer X https://codeworkou... CodeWorkout X270: Recursion Programming Exercise: Count Characters For function countChr() write the missing part of the recursive call. This function should return the number of times that the letter "A" appears in string "str". Recall that str.substring(a) will return the substring of str from position a to the end of str, while str.substring (a, b) will return the substring of str starting at position a and continuing to (but not including) the character at position b. Examples: countChr ("ctcoWCAt") -> 1 Your AnsSwer: 1 public int countChr(String str) { 2. if (str.length() return 0; } (0 4. { int count = 0; www. 5. 9. if (str.substring(0, 1).equals("A")) { count = 1 7. { 9. return count + > 1:10 AM 50°F Clear 12/4/2021 呼arrow_forwardWrite 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_forward
- Write a recursive Fibonacci function that computes the Fibonacci number for input n and prints each value computed in the series at each recursive step in the sequence from 0 to n, all in one line on the console. (In python)arrow_forwardWrite a recursive function that returns the sum of the digits of an integer.int sumOfDigits(int x);arrow_forward4. 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_forward
- Exercise 1: The number of combinations CR represents the number of subsets of cardi- nal p of a set of cardinal n. It is defined by C = 1 if p = 0 or if p = n, and by C = C+ C in the general case. An interesting property to nxC calculate the combinations is: C : Write the recursive function to solve this problem.arrow_forwardPython only** Use recursive function* Define countBetween with 2 parameters Use def to define countBetween with 2 parameters thas two parameters: a starting number and an ending number, and counts up (i.e., prints consecutive integers) from the starting number to the ending number. If the numbers are the same, it just prints that number; if the ending number is lower than the starting number, it prints nothing. Do not use any kind of loop Within the definition of countBetween with 2 parameters, do not use any kind of loop. Call countBetween Within the definition of countBetween with 2 parameters, call countBetween in at least one place. Python only** Use recursive function* Define countThereAndBack with 2 parameters Use def to define countThereAndBack with 2 parameters after reaching the ending number, it also counts back down to the starting number. It accepts the same two parameters defining starting and ending numbers it should print nothing if the starting number is…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_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