Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 14.1, Problem 11STE
Trace the recursive solution you made to Self-Test Exercise 5.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Ex. 01 : Recursion
About
So far, we have learned that we can perform repetitive tasks using loops. However, another way is by creating methods that call themselves. This programming technique is called recursion
and, a method that calls itself within it's own body is called a recursive method. One use of recursion is to perform repetitive tasks instead of using loops, since some problems seem to be
solved more naturally with recursion than with loops.
To solve a problem using recursion, it is broken down into sub-problems. Each sub-problem is similar to the original problem, but smaller in size. You can apply the same approach to each
sub-problem to solve it recursively.
All recursive methods use conditional tests to either
1. stop or
2. continue the recursion.
Each recursive method has the following characteristics:
1. end/terminating case: One or more end cases to stop the recursion.
2. recursive case: reduces the problem in to smaller sub-problems, until it reaches (becomes) the end…
1. Let product(n,m) be a recursive addition-subtraction method for multiplying two positive integers. Recursive cases for m = 1 and m < 1 make this method. The return value should be n plus a recursive product() call with n and m - 1. Test a Java method.
Is the recursive solution to the triangle number the best way to obtain the triangle number?
A.
Yes, because recursive solutions are always efficient.
B.
Yes, because the shape of the triangle number diagram lends itself to a recursive solution.
C.
No, the triangle number can be found in a more efficient manner.
D.
None of the above are true.
Chapter 14 Solutions
Problem Solving with C++ (9th Edition)
Ch. 14.1 - Prob. 1STECh. 14.1 - Prob. 2STECh. 14.1 - Prob. 3STECh. 14.1 - Prob. 4STECh. 14.1 - Prob. 5STECh. 14.1 - If your program produces an error message that...Ch. 14.1 - Write an iterative version of the function cheers...Ch. 14.1 - Write an iterative version of the function defined...Ch. 14.1 - Prob. 9STECh. 14.1 - Trace the recursive solution you made to Self-Test...
Ch. 14.1 - Trace the recursive solution you made to Self-Test...Ch. 14.2 - What is the output of the following program?...Ch. 14.2 - Prob. 13STECh. 14.2 - Redefine the function power so that it also works...Ch. 14.3 - Prob. 15STECh. 14.3 - Write an iterative version of the one-argument...Ch. 14 - Prob. 1PCh. 14 - Prob. 2PCh. 14 - Write a recursive version of the search function...Ch. 14 - Prob. 4PCh. 14 - Prob. 5PCh. 14 - The formula for computing the number of ways of...Ch. 14 - Write a recursive function that has an argument...Ch. 14 - Prob. 3PPCh. 14 - Prob. 4PPCh. 14 - Prob. 5PPCh. 14 - The game of Jump It consists of a board with n...Ch. 14 - Prob. 7PPCh. 14 - Prob. 8PP
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Write statements to accomplish each of the following: Display the value of the seventh element of character arr...
C How to Program (8th Edition)
1 void product() { 2int, a = 6; 3int b = 5; 4int c = 4; 5int result = a b c; 6System.out.printf("Result is %d...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Consider the adage Never ask a question for which you do not want the answer. a. Is following that adage ethica...
Experiencing MIS
What is an accessor method? What is a mutator method?
Java: An Introduction to Problem Solving and Programming (7th Edition)
Consider the adage Never ask a question for which you do not want the answer. a. Is following that adage ethica...
Experiencing MIS
How many lines of output does the following function print? Give your answer as a function of n. Assume n 1.
Computer Systems: A Programmer's Perspective (3rd 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
- Indirect recursion is when function A calls function B, which in turn calls function A. is it true or false.arrow_forwardWrite a recursive function for int powerOfTwo (int k). The function determines the value of 2k. (Note: k is a positive integer). Example, when k=0 the function returns 1 and when k-3 the function returns 8. To show that your code is correct, give the recursive trace for powerOfTwo (2) that returns 4.arrow_forwardHelp me in recursion. Your task is to print I am coder using recursion for 7 times In elixir programming languagearrow_forward
- One-friend recursion vs iteration. 1. Your objective is to receive the tuple a1, a2,..., a and return the tuple an, an1,..., a1 that has been inverted. You will only take an element off of one end or put an element back on one end because you are being lazy. But you have friends in recursion who can assist you.Please provide the recursive code as well as a paragraph with the friend's description of the algorithm.2. Now imagine that you lack friends but have a stack. Quickly design an iterative programme to address this issue. Include loop invariants and other crucial stages that are necessary to describe an iterative method.3. Trace both of these scripts separately. On a computer, step by step compare and contrast their calculations.arrow_forwardWhich of the following is/are true regarding the characteristics of recursion? a.Every recursive call reduces the original problem, bringing it increasingly closer to a base case until it becomes that case. b.Recursive method requires less memory than an iterative method. c. It is possible to convert every recursive method to an iterative method. d.The method is implemented using an if-else or a switch statement that leads to different cases. e.One or more base cases are used to stop recursion.arrow_forwardWrite a recursive version of the function reverse(s), which reverses thestring s in place.arrow_forward
- When recursion is used to solve a problem, why must the recursive method call itself to solve a smaller version of the original problem?arrow_forward1. Let product(n,m) be a recursive method that computes the product of two positive integers, using only addition and subtraction. To make this method a recursive one, you are to make a) a base case when m = 1, b) a general case when m ≠ 1. For a general case, the return value should be n plus the result of a recursive call to the method product() with parameters n and m - 1. Write a short Java code for this method, along with a test program.arrow_forwardWrite a recursive function that returns true if the digits of a positive integer are in increasing order; otherwise, the function returns false. Also, write a program to test your function.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Computational Software for Intelligent System Design; Author: Cadence Design Systems;https://www.youtube.com/watch?v=dLXZ6bM--j0;License: Standard Youtube License