Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
which of the following methods is recursive ?
public static int length(String str) { if (str == null || str.equals("")) return 0: else return 1 + length(str.substring(1)); }
|
||
public static int length(Strin str) { if (str == null || str.equals("")) return 0: else return 1; }
|
||
public static int length(Strin str) { if (str == null || str.equals("")) return 0: else return 1 + len(str.substring(1)); }
|
||
public static int length(String str) { if (str == null || str.equals("")) return 0: } |
java
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
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
- a.Turkeys of Thanksgiving coming! b.Thanksgiving coming! c.Thanksgiving of Turkeys d.None of the abovearrow_forwardFor questions 1 – 2, use the following recursive method.public int question1_2(int x, int y){if (x == y) return 0;else return question1_2(x-1, y) + 1;} 2) Calling this method will result in infinite recursion if which condition below is initially true?a) (x = = y)b) (x != y)c) (x > y)d) (x < y)e) (x = = 0 && y != 0)arrow_forwardWhich recursive method would return a value of 210 if result(7) was called? Question 1 options: public int result(int a){ if (a == 1){ return a; } else{ return a * result(a - 2); }} public int result(int a){ if (a == 1){ return 1; } else{ return a * result(a - 2); }} public int result(int a){ if (a == 1){ return a + 1; } else{ return a * result(a - 2); }} public int result(int a){ if (a == 1){ return 1; } else{ return a * result(a - 1); }}arrow_forward
- Consider the following recursive method: public int recursiveMethod (int n) if (n <= 0) return 0; else int smaller = n - 1; return recursiveMethod (smaller) + n (n - 1); What is the integer return of a call recursiveMethod (5)? 36 39 40 44 Next Page Previous Pagearrow_forwardConsider the following recursive method: Public static int Fib(int a1, int a2, int n){ if(n == 1) return a1; else if (n == 2) return a2;else return Fib(a1, a2, n-1) + Fib(a1, a2, n-2);} Please draw the recursion trace for Fib(2,3,5)arrow_forwardPlease explain the questions related to the code below: //1. Why is 20 printed 3 times and why does it start with 1, but end with 2? //2. What is the base case for this recursive method and why? //3. How would you implement this using a loop? //4. What is each if statement checking? //5. Would a solution to this using loops require more or less code and would it be more or less effecient? //6. Why is recursion a good choice to solve this problem? //7. How can recursion become infinite? //8. When is recursion appropriate? /* Load the code below into a cloud compiler and run each method one at a time by removing the comments for the method. Walk through the code as a group and explore how the code works. Submit the answers to the numbered questions for credit. */ public class DemoRecur { //Simple statement designed to show control flow in recursion public static void printDemo(int x, int max) {…arrow_forward
- Write a recursive method to determine whether a String contains a 'q' not immediately followed by a 'u' (ignoring capitalization). In other words: • the word does contain at least one 'q' • and that q is followed by anything except a 'u' Carefully review the provided driver program to see example test cases. The method header is: public static boolean qNotFollowedByU(String word)arrow_forwardA recursive method with no base case? 1.causes an infinite loop 2.generates no output 3.does not start 4.all of the answersarrow_forwardsolve q4 only pleasearrow_forward
arrow_back_ios
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