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(l, 1) A(l, 2) A(l, 3) A(2,2) A(3,2)
Want to see the full answer?
Check out a sample textbook solutionChapter 14 Solutions
Starting Out with C++: Early Objects (9th Edition)
Additional Engineering Textbook Solutions
Modern Database Management
Starting Out With Visual Basic (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Degarmo's Materials And Processes In Manufacturing
SURVEY OF OPERATING SYSTEMS
Management Information Systems: Managing The Digital Firm (16th Edition)
- Consider the recursive procedure which computes the nth Fibonacci number is the one below. procedure Fl (n) //a function which returns the nth Fibonacci number.// if n < 2 then return(n) else return (F2(2,n,1,1)) endif end Fl procedure F2(i,n,x,y) if iarrow_forwardBy using a recursive function to find s value: S= 2/x – 4/x + 6/x – 8/x .. 2n/xarrow_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_forward
- Ackermann’s Functionarrow_forwardFor funX |C Solved xb Answer x+ CodeW X https://codeworko... 田) CodeWorkout X267: Recursion Programming Exercise: Cumulative Sum For function sumtok, write the missing recursive call. This function returns the sum of the values from1 to k. Examples: sumtok(5) -> 15 Your Answer: 1 public int sumtok(int k) { 2. } (0 => ) return 0; 3. } else { return > 6. { Check my answer! Reset Next exercise 1:09 AMarrow_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
- 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_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_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
- Beeblebrox question helparrow_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_forwardWrite a recursive function that returns the sum of the digits of an integer.int sumOfDigits(int x);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