Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 5, Problem 18C

Explanation of Solution

Recursive method for palindrome:

The recursive method for palindrome is given below:

Create the method palindrome() that accepts the input parameter as “s”, “low”, and “high” to check the low index of string is equal to high index of string and recursively call palindrome() method by passing the parameters of “s”, “low+1”, and “high-1” to check the string is palindromes or not.

//Define the palindrome() method

public static boolean palindrome(String s, int low, int high)

{

  //Check whether "low" is less than "high"

  if(low < high)

  {

/*Check whether first index of string and last index of string is equal and then call palindrome() method recursively. */

if (s.charAt(low)==s.charAt(high-1) && palindrome(s, low + 1, high-1))

  //Return true, string is palindrome

  return true;

/*Otherwise, return false that the string is not palindrome. */

  else

  return false;

  }

/*Otherwise, return true that the string is palindrome. */

  else

  //Assume in this case, low == high

  return true;

}

Explanation:

In the above code,

  • It accepts the input parameter as “s”, “low”, and “high”.
  • Check whether the “low” is less than “high”. If yes,
    • Check whether the index of “low” string is equal to index of “high-1” string and Call palindrome() method by passing the parameters as “s”, “low+1”, and “high-1” recursively. If yes,
      • Return true that the given string is palindrome.
    • Otherwise, return false that the given string is not palindrome...

Blurred answer
Students have asked these similar questions
Don't use chatgpt or any other AI
Don't use chatgpt or any other AI
Given a relation schema R = (A, B, C, D, E,G) with a set of functional dependencies F {ABCD BC → DE B→ D D→ A}. (a) Show that R is not in BCNF using the functional dependency A → BCD. (b) Show that AG is a superkey for R (c) Compute a canonical cover Fc for the set of functional dependencies F. Show your work. (d) Give a 3NF decomposition of R based on the canonical cover found in (c). Show your work. (e) Give a BCNF decomposition of R using F. Show your work.
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Principles of Information Systems (MindTap Course...
Computer Science
ISBN:9781285867168
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Introduction to Big O Notation and Time Complexity (Data Structures & Algorithms #7); Author: CS Dojo;https://www.youtube.com/watch?v=D6xkbGLQesk;License: Standard YouTube License, CC-BY