Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 12, Problem 2SA
In this chapter, the rules given for calculating the factorial of a number are as follows:
If n = 0 then factorial (n) = 1
If n . 0 then factorial (n) = n × factorial (n - 1)
If you were designing a function from these rules, what would the base case be? What would the recursive case be?
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
In this chapter, the rules given for calculating the factorial of a number are as follows:If n = 0 then factorial(n) = 1If n . 0 then factorial(n) = n × factorial(n – 1)If you were designing a function from these rules, what would the base case be? What wouldthe recursive case be?
Each of the following recursive function definitions contains an error. Briefly but fully and clearly explain what is wrong with each definition.
f(x) = 3*f(x-5) where x is a positive integer.
f(0) = 7
2. g(x) = 2 - 4*g(x) where x is a positive integer.
g(1) = 3
g(2) = 4
8. Ackerman's Function
Ackermann's Function is a recursive mathematical algorithm that can be used to test how well a system optimizes its performance of recursion. Design a function ackermann(m, n), which solves Ackermann's function. Use the following logic in your function:
If m = 0 then return n + 1
If n = 0 then return ackermann(m-1,1)
Otherwise, return ackermann(m-1,ackermann(m,n-1))
Once you've designed yyour function, test it by calling it with small values for m and n.
Use Python.
Chapter 12 Solutions
Starting Out with Python (4th Edition)
Ch. 12.2 - It is said that a recursive algorithm has more...Ch. 12.2 - Prob. 2CPCh. 12.2 - What is a recursive case?Ch. 12.2 - What causes a recursive algorithm to stop calling...Ch. 12.2 - What is direct recursion? What is indirect...Ch. 12 - Prob. 1MCCh. 12 - A function is called once from a program's main...Ch. 12 - Prob. 3MCCh. 12 - Prob. 4MCCh. 12 - Prob. 5MC
Ch. 12 - Prob. 6MCCh. 12 - Any problem that can be solved recursively can...Ch. 12 - Actions taken by the computer when a function is...Ch. 12 - A recursive algorithm must _______ in the...Ch. 12 - A recursive algorithm must ______ in the base...Ch. 12 - An algorithm that uses a loop will usually run...Ch. 12 - Some problems can be solved through recursion...Ch. 12 - It is not necessary to have a base case in all...Ch. 12 - In the base case, a recursive method calls itself...Ch. 12 - In Program 12-2 , presented earlier in this...Ch. 12 - In this chapter, the rules given for calculating...Ch. 12 - Is recursion ever required to solve a problem?...Ch. 12 - When recursion is used to solve a problem, why...Ch. 12 - How is a problem usually reduced with a recursive...Ch. 12 - What will the following program display? def...Ch. 12 - Prob. 2AWCh. 12 - The following function uses a loop. Rewrite it as...Ch. 12 - Prob. 1PECh. 12 - Prob. 2PECh. 12 - Prob. 3PECh. 12 - Largest List Item Design a function that accepts a...Ch. 12 - Recursive List Sum Design a function that accepts...Ch. 12 - Prob. 6PECh. 12 - Prob. 7PECh. 12 - Ackermann's Function Ackermann's Function is a...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Draw the three Mohrs circles that describe each of the following states of stress.
Mechanics of Materials (10th Edition)
Design an algorithm that prompts the user to enter a number in the range of 1 through 100 and validates the inp...
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
How would you calculate or estimate Tm for a horizontal bandsaw cutting a 3-in. round of 1040 steel.
Degarmo's Materials And Processes In Manufacturing
For the circuit shown, use the node-voltage method to find v1, v2, and i1.
How much power is delivered to the c...
Electric Circuits. (11th Edition)
T F: The multiplication operator has higher precedence than the addition operator.
Starting Out With Visual Basic (8th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Recursion in programming is described as when a function/method makes a direct or indirect call to itself. Which of the features is not valid for a recursive function. Select one: a. The Recursive calls can be more then one b. The Recursive Call – the function calls itself with an input which is a step closer to the stop condition c. The Stoping Conditions can be more than one d. The Recursive call is optional. e. A Stop Condition – the function returns a value when a certain condition is satisfied, without a further recursive callarrow_forwardWrite a recursive function to find the factorial of a number.int factorial(int n);arrow_forwardConsider 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_forward
- When a recursive function is run, there is an additional demand placed on the memory of the computer and the amount of time it takes to run the programme.arrow_forwardUsing Java programming write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 7 * 4=4+4+4+4+4+4+4arrow_forwardUsing recursive functions in Python, given three letters in the alphabet, get their permutations together with the combinations of any two letters from it.arrow_forward
- The following recursive function takes three positive integer arguments: def compute(n,x,y) : if n==0 : return x return compute(n-1,x+y,y) What is the value returned by the compute function? n*x+y x+y x+n*y x What if: will the returned value be for the compute function defined in the question above if the argument n is negative? x x-n*y x+n*y The function will never return a value.arrow_forwardPascal's triangle is a useful recursive definition that tells us the coefficients in the expansion of the polynomial (x + a)^n. Each element in the triangle has a coordinate, given by the row it is on and its position in the row (which you could call a column). Every number in Pascals triangle is defined as the sum of the item above it and the item above it and to the left. If there is a position that does not have an entry, we treat it as if we had a 0 there. *picture of the pascals triangle* Given the following recursive function signature, write the recursive function that takes a row and a column and finds the value at that position in the triangle. Assume that the triangle starts at row 0 and column 0. Examples: pascal(2, 1) -> 2, pascal(1, 2) -> 0 public int pascal(int row, int column) { }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_forward
- Please help. I don’t understandarrow_forwardQuestionarrow_forward3. Observe the following formulae: fin) = 1 fin) = 3 + f(n-1) fin) = 2 + f(n-1) if n=0 if n is even if n is odd a) Write a direct recursive function based on the formulae above. The function prototype is given as: int f(int n); Note: You don't have to worry about n being less than 0, but beware of 0 being an even number. b) Using mutual recursion and based on the formulae above, complete the function definition for the following function prototypes: int fodd (int n) ; int fEven (int n); c) Write a complete C program to test the direct and mutual recursions that you have written in Parts (a) and (b). Prompt the user for n values.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Computational Software for Intelligent System Design; Author: Cadence Design Systems;https://www.youtube.com/watch?v=dLXZ6bM--j0;License: Standard Youtube License