Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 18.9, Problem 18.9.1CP
Which of the following statements are true?
- a. Any recursive method can be converted into a nonrecursive method.
- b. Recursive methods take more time and memory to execute than nonrecursive methods.
- c. Recursive methods are always simpler than nonrecursive methods.
- d. There is always a selection statement in a recursive method to check whether a base case is reached.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Which 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.
Question)
Which of the following is NOT a good strategy for designing recursive methods?
A recursive method should include at least one conditional statement.
A recursive method should establish a base case.
A recursive method should reduce the problem to a smaller problem or problems and call itself recursively to solve the smaller problem(s).
When the base case is reached stop the program and display results.
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 18 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 18.2 - What is a recursive method? What is an infinite...Ch. 18.2 - Prob. 18.2.2CPCh. 18.2 - Show the output of the following programs and...Ch. 18.2 - Prob. 18.2.4CPCh. 18.2 - Prob. 18.2.5CPCh. 18.2 - Write a recursive mathematical definition for...Ch. 18.3 - Prob. 18.3.1CPCh. 18.3 - What is wrong in the following methods?Ch. 18.3 - Prob. 18.3.3CPCh. 18.4 - Describe the characteristics of recursive methods.
Ch. 18.4 - Prob. 18.4.2CPCh. 18.4 - Prob. 18.4.3CPCh. 18.5 - Prob. 18.5.1CPCh. 18.5 - Prob. 18.5.2CPCh. 18.5 - What is a recursive helper method?Ch. 18.6 - Prob. 18.6.1CPCh. 18.6 - How does the program get all files and directories...Ch. 18.6 - How many times will the getSize method be invoked...Ch. 18.6 - Will the program work if the directory is empty...Ch. 18.6 - Will the program work if line 20 is replaced by...Ch. 18.6 - Will the program work if lines 20 and 21 are...Ch. 18.7 - Prob. 18.7.1CPCh. 18.8 - Prob. 18.8.1CPCh. 18.8 - Prob. 18.8.2CPCh. 18.8 - How many times is the displayTriangles method...Ch. 18.8 - Prob. 18.8.4CPCh. 18.8 - Prob. 18.8.5CPCh. 18.9 - Which of the following statements are true? a. Any...Ch. 18.9 - Prob. 18.9.2CPCh. 18.10 - Identify tail-recursive methods in this chapter.Ch. 18.10 - Rewrite the fib method in Listing 18.2 using tail...Ch. 18 - Prob. 18.1PECh. 18 - Prob. 18.2PECh. 18 - (Compute greatest common divisor using recursion)...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Sum series) Write a recursive method to compute...Ch. 18 - (Fibonacci series) Modify Listing 18.2,...Ch. 18 - Prob. 18.8PECh. 18 - (Print the characters in a string reversely) Write...Ch. 18 - (Occurrences of a specified character in a string)...Ch. 18 - Prob. 18.11PECh. 18 - (Print the characters in a string reversely)...Ch. 18 - (Find the largest number in an array) Write a...Ch. 18 - (Find the number of uppercase letters in a string)...Ch. 18 - Prob. 18.15PECh. 18 - (Find the number of uppercase letters in an array)...Ch. 18 - (Occurrences of a specified character in an array)...Ch. 18 - (Tower of Hanoi) Modify Listing 18.8,...Ch. 18 - Prob. 18.19PECh. 18 - (Display circles) Write a Java program that...Ch. 18 - (Decimal to binary) Write a recursive method that...Ch. 18 - (Decimal to hex) Write a recursive method that...Ch. 18 - (Binary to decimal) Write a recursive method that...Ch. 18 - (Hex to decimal) Write a recursive method that...Ch. 18 - Prob. 18.25PECh. 18 - (Create a maze) Write a program that will find a...Ch. 18 - (Koch snowflake fractal) The text presented the...Ch. 18 - (Nonrecursive directory size) Rewrite Listing...Ch. 18 - (Number of files in a directory) Write a program...Ch. 18 - (Game: Knights Tour) The Knights Tour is an...Ch. 18 - (Game: Knights Tour animation) Write a program for...Ch. 18 - (Game: Eight Queens) The Eight Queens problem is...Ch. 18 - Prob. 18.35PECh. 18 - (Sierpinski triangle) Write a program that lets...Ch. 18 - (Hilbert curve) The Hilbert curve, first described...Ch. 18 - (Recursive tree) Write a program to display a...Ch. 18 - Prob. 18.39PE
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Define a class CircleCalculator that hat only two methods, getArea and getCircumference. These methods return t...
Java: An Introduction to Problem Solving and Programming (7th Edition)
(Fisher-Yates Shuffling Algorithm) Research the Fisher-Yates shuffling algorithm online, then use it to reimple...
C How to Program (8th Edition)
(Population growth) A certain city had a population of 25000 in 1960 and a population of 30,000 in 1970. Assume...
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
A program is a set of _______.
Starting Out with C++ from Control Structures to Objects (9th Edition)
What are the advantages and disadvantages of implicit declarations?
Concepts Of Programming Languages
A file that contains a Flash animation uses the __________ file extension. a. .class b. .swf c. .mp3 d. .flash
Web Development and Design Foundations with HTML5 (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
- Which of the following statements are correct? Iteration is always worse than recursion. Recursion uses more memory than an iterative approach. Recursion uses less memory than an iterative approach. O Iterative function is always easier to write than recursion.arrow_forwardJAVA Question 2: For two integers m and n, their GCD (Greatest Common Divisor) can be computed by a recursive method. Write a recursive method gcd(m,n) to find their Greatest Common Divisor. Method body: If m is 0, the method returns n. If n is 0, the method returns m. If neither is 0, the method can recursively calculate the Greatest Common Divisor with two smaller parameters: One is n, the second one is m mod n (or m % n). The recursive method cannot have loops. Note: although there are other approaches to calculate Greatest Common Divisor, please follow the instructions in this question, otherwise you will not get the credit. main method: Prompt and read in two numbers to find the greatest common divisor. Call the gcd method with the two numbers as its argument. Print the result to the monitor. Example program run: Enter m: 12 Enter n: 28 GCD(12,28) = 4 And here is what I have so far, package CSCI1302;import java.util.*;public class RecursionDemo { public static void…arrow_forwardRecursion 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_forward
- 1. Write a recursive method expFive(n) to compute y=5^n. For instance, if n is 0, y is 1. If n is 3, then y is 125. If n is 4, then y is 625. The recursive method cannot have loops. Then write a testing program to call the recursive method. If you run your program, the results should look like this: > run RecExpTest Enter a number: 3 125 >run RecExpTest Enter a number: 3125 2. For two integers m and n, their GCD(Greatest Common Divisor) can be computed by a recursive function. Write a recursive method gcd(m,n) to find their Greatest Common Divisor. Once m is 0, the function returns n. Once n is 0, the function returns m. If neither is 0, the function can recursively calculate the Greatest Common Divisor with two smaller parameters: One is n, the second one is m mod n. Although there are other approaches to calculate Greatest Common Divisor, please follow the instructions in this question, otherwise you will not get the credit. Meaning your code needs to follow the given algorithm. Then…arrow_forwardIf your first name starts with a letter from A-J inclusively: Write a recursive method that takes a string as argument and determines if the string has more vowels than consonants. Test the method by asking the user to enter a string. Hint: Write your recursive method to first count vowels and consonants.arrow_forwardQUESTION 9 There are several rules to keep in mind when writing a recursive function. Select all of them from the following list. of al Tust A. The recursive function may not call any other function or method. B. The value of all arguments passed to the recursive function must change for every recursive call. C. The recursive method must cal the main function in order to begin. D.There must be a clearly stated base case. CE. The function must contain a break statement to end the recursion. OF. The recursive function may not include a return statement. G. Recursive calls to the function must converge on the base case. is called. H.One or more arguments passed to the function must change in value each time the function iarrow_forward
- Write a recursive function that takes a positive integer and returns the factorial of that integer. Attention, the function must be recursive, and its name must be "fatorial".arrow_forwardPlease can be handwritten. Question 2: Implementing a Recursive Function . Write recursive function, recursionprob(n), which takes a positive number as its argument and returns the output as shown below. The solution should clearly write the steps as shown in an example in slide number 59 and slide number 60 in lecture slides. After writing the steps, trace the function for “recursiveprob(5)” as shown in an example slide number 61. Function Output: >> recursionprob(1) 1 >> recursionprob(2) 1 4 >> recursionprob(3) 1 4 9 >>recrusionprob(4) 1 4 9 16arrow_forwardWrite and test the following recursive methods:1. A method that, for a positive integer n, prints odd numbers between 1 and n.2. A method that, for a positive integer n, prints odd numbers between n and 1.3. A method to add the first n terms of the series: 1 +12−13+14−15…1?4. A recursive version of the following method:void cubes(int n) {for (int i = 1; i <= n; i++)System.out.print(i * i * i, " ");}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 Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Computational Software for Intelligent System Design; Author: Cadence Design Systems;https://www.youtube.com/watch?v=dLXZ6bM--j0;License: Standard Youtube License