
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

Transcribed Image Text:2. Consider the following recursive algorithm implemented as a Java method:
public static boolean isPalindrome (String s) {
if (s.length()
return true;
}
==
0) {
}
else if (s.length()
return true;
}
==
1) {
}
else if (s.charAt(0) != s.charAt(s.length()-1)) {
return false;
}
else {
return isPalindrome (s.substring(1, s.length()-2));
Assuming that the recursive call takes 15 basic operations, a return statement
takes 3 basic operations and that any of the if statements takes 7 basic
operations, give a recurrence describing the worst-case running time for this
algorithm.
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
- Consider the following recursive method in Java that determines ifa string is a palindrome (i.e., reads the same forward or backwards) or not: Public boolean isPalindrome ( String str ){If( str.length() ≤ 1 )return true;elsereturn ( str.charAt (0) == str.charAt( str.length() – 1 ) &&isPalindrome( str.substring(1..str.length() - 1)));} // end of isPalindrome a. Explain convincingly why the recurrence below for f(n), where n is the length of the string parameter str, is a correct expression for the number of primitive operationsrequired by a call isPalindrome.t(0) = Θ(1)t(1) = Θ(1)t(?) = t(? − 2) + Θ(1)b. Show that t(n) = Θ(n), solves the recurrence for t(n) in (a) above.arrow_forwardThe following recursive method called z is created. This method accepts two parameters: A string s, and an integer index The code in the method is: if (index == s.length()) return ""; <------ base case if(index % 2 == 0) return ""+ s.charAt(index) + z(s,index+1); <---- recursive call else return z(s,index+1); <----- recursive call What would be the output with the call: z("javajavajava",0);arrow_forwardConsider a recursive method below. static void mysteryRecursion (String x) { if (x.length() < 1) { System.out.println(x); } else { System.out.println (x.charAt (0) + " " + x.charAt (x.length () - 1)) ; mysteryRecursion (x.substring (1, x.length () - 1)); What gets printed if I make the method call mysteryRecursion("helloworld");arrow_forward
- The method is in fact faulty. Give a test input (String) that will make the method to fail -- i.e., it will throw an exception when it is executed with the input).arrow_forwardConvert the following Java method to a functionally equivalent iterative method without any recursion. public static double fun(int n) { if (n == 0) return 0; else return 1.0/(n+fun(n-1)); }arrow_forwardWrite a recursive method in java that sums all values between s and n inclusive /* assume s is less than or equal to n to start */ public static int sum(int s, int n) { }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_forwardWrite a recursive method oddSum that takes a positive odd integer n and returns the sum of odd integers from 1 to n.arrow_forwardPLZ help with the following: In Java Write a program using recursion to display all valid (i.e. properly open and closed) combinations of n-pairs of parentheses.arrow_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