Starting Out with Programming Logic and Design (4th Edition)
4th Edition
ISBN: 9780133985078
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
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?
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) {
}
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…
Chapter 13 Solutions
Starting Out with Programming Logic and Design (4th Edition)
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
- 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+4arrow_forwardWhen a program has a logic error and reaches an infinite recursion the program is always going to crash (runtime error). True O Falsearrow_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
- Recursion is the best and the fastest way to solve any problem.True or Falsearrow_forwardPLZ help with the followig IN JAVA Pick the best answer Recursive methods may include a recursive call Recursive methods may not use iteration Recursive methods must include a recursive call none of the abovearrow_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
- Java programming language Write a recursion method to sum the odd numbers a) from 100 to 0 b) from 0 to 100 and then test it.arrow_forwardWhen recursion is used to solve a problem, why must the recursive method call itself to solve a smaller version of the original problem?arrow_forwardJava - When the compiler compiles your program, how is a recursive call treated differently than a non-recursive method call? What property of fractals lends itself to recursive thinking?arrow_forward
- Question 5 Dk .Full explain this question and text typing work only We should answer our question within 2 hours takes more time then we will reduce Rating Dont ignore this linearrow_forwardPython language only Suppose you are working in the pizza company named Dominoes. Dominoes provides the best in class pizza in the world so While dealing with the coustomer you got a number on every billed amount. SO here your task is to identifiy that the billing amount is a magic number or not. A number is said to be a magic number, if the sum of its digits are calculated till a single digit recursively by adding the sum of the digits after every addition. If the single digit comes out to be 1,then the number is a magic number. Input : 1234Output : Yes it isInput : 12345Output : No it is notarrow_forwardWrite a recursive program that takes a positive integer as an input and returns the sum of the digits of the integer. (Example: If the input is 45678, then output will be 30.)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 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