Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
5th Edition
ISBN: 9780134801155
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 13, 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 module from these rules, what would the base case be? What would the recursive case be?
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Pascal'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) {
}
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?
Using 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+4
Chapter 13 Solutions
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Ch. 13.2 - It is said that a recursive algorithm has more...Ch. 13.2 - Prob. 13.2CPCh. 13.2 - What is a recursive case?Ch. 13.2 - What causes a recursive algorithm to stop calling...Ch. 13.2 - What is direct recursion? What is indirect...Ch. 13 - Prob. 1MCCh. 13 - A module is called once from a programs main...Ch. 13 - The part of a problem that can be solved without...Ch. 13 - Prob. 4MCCh. 13 - Prob. 5MC
Ch. 13 - Prob. 6MCCh. 13 - Any problem that can be solved recursively can...Ch. 13 - Actions taken by the computer when a module is...Ch. 13 - A recursive algorithm must _______ in the...Ch. 13 - A recursive algorithm must _____ in the base case....Ch. 13 - An algorithm that uses a loop will usually run...Ch. 13 - Some problems can be solved through recursion...Ch. 13 - It is not necessary to have a base case in all...Ch. 13 - In the base case, a recursive method calls itself...Ch. 13 - In Program 13-2, presented earlier in this...Ch. 13 - In this chapter, the rules given for calculating...Ch. 13 - Is recursion ever required to solve a problem?...Ch. 13 - When recursion is used to solve a problem, why...Ch. 13 - How is a problem usually reduced with a recursive...Ch. 13 - What will the following program display? Module...Ch. 13 - What will the following program display? Module...Ch. 13 - The following module uses a loop. Rewrite it as a...Ch. 13 - Prob. 1PECh. 13 - Prob. 2PECh. 13 - Recursive Array Sum Design a function that accepts...Ch. 13 - Prob. 4PECh. 13 - Prob. 5PECh. 13 - Ackermanns Function 7. Ackermanns Function is a...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
When displaying a Java applet, the browser invokes the _____ to interpret the bytecode into the appropriate mac...
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Write the function htoi(s), which converts a suing of hexadecimal digits (including an optional 0x or 0X) into ...
C Programming Language
Alphabetic Telephone Number Translator Many companies use telephone numbers like 555-GET-FOOD so the number is ...
Starting Out with Java: From Control Structures through Objects (6th Edition)
Write code to implement the following function: / Generate mask indicating leftmost 1 in x. Assume w=32. For ...
Computer Systems: A Programmer's Perspective (3rd Edition)
For each of the following situations, tell which type of loop (while, do-while, or for) would work best: a. Sum...
Absolute Java (6th Edition)
Implement a performance-measuring environment simulator for the vacuum-cleaner world depicted in Figure 2.2 and...
Artificial Intelligence: A Modern Approach
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
- Task 1 Count the number of vowels in a phrase using recursion only. You can think of this problem as "I can count the number of vowels in this phrase by counting the number of vowels in the first character, then counting the number of vowels in the rest of the phrase." We define a vowel as being A, E, I, O or U. This is one of those problems that can just as easily be solved with traditional programming structures such as a loop - but we're asking you to use recursion for the exercise. Consider: what replaces the loop structure? When will we stop recursion? Task 2 The constant e (Euler's number) is approximated by the following sequence: 1₁ n! where the number of terms in the sequence is sufficient to generate the required precision in decimal places. 1+ 2! + ... We say that there is some value epsilon (e) such that, when the change in the approximation from one term to the next is less than said epsilon, we have reached sufficient precision. That is, when the term you're proposing to…arrow_forwardQuestion 5 When writing a recursive method, O you do not need to know ahead of time exactly how many levels of recursion will occur. O you must keep count of how many recursion call levels you have traversed. O you must make sure the method does not take any input parameters.arrow_forwardWhat is the overhead involved in the execution of a recursive function, both in terms of the amount of memory space and the amount of time taken by the computer?arrow_forward
- When a program has a logic error and reaches an infinite recursion the program is always going to crash (runtime error). True O Falsearrow_forwardRecursive functions are ones that repeat themselves repeatedly.arrow_forwardWrite the recursive function based on the following formula in Visual Basic code: if n=0 f(n) = 1 if n = 1 F(n- 1) + F(n – 2) if n>1arrow_forward
- In a recursive algorithm, the goal is to solve a problem by breaking it into smaller sub-problems to solve. This is accomplished by constructing an algorithm using two important components. What are these components, what is the purpose of each?arrow_forwardNot recursivearrow_forwardQuestion 15 base: a(1) = 12 recursion: a(n) = a(n-1) - 5 A recursive formula can be implemented in Python and then used to provide the nth term in a series. Which of the following recursive programs implements the recursive formula below and prints out its 5th term (-8): def recursive_3(num): if num == 1: return 12 return recursive_3(num - 1) - 5 print('rec_3 ', recursive_3(5)) esc def recursive_3(num): if num == 1; https://app.sophia.org/spcc/introduction-to-python-programming-milestone-2-1/15/12632 F1 F2 Mark this question 80 F3 2 000 3 4 F4 F5 5 2..arrow_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_forwardPythonDesign a recursive function that accepts an integer argument, n, and prints the number 1 up through n.arrow_forwardPython Question :Which of the following describes the base case in a recursive solution? Group of answer choices the way to return to the main function the case in which the problem is solved through recursion the way to stop the recursion a case in which the problem can be solved without recursionarrow_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 LearningProgramming 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
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