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

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 5, Problem 2R

Explanation of Solution

Modified Recursive binary search algorithm:

The modified recursive binary search method is given below:

//Define the binarySearch() method

public static int binarySearch(int[ ] data, int target, int low, int high)


  //Check "low" is greater than "high"

  if (low > high)

  //Return the -1

  return −1;

  //Execute the else part



/*Add "low" and "high" and the result is divided by 2 and then store the result element to "mid". */

int mid = (low + high) / 2;

  //Check "target" is equal to "data[mid]"

if (target == data[mid])

  //Return the index of search element

  return mid;

  //Execute the else part

else if (target < data[mid])

  //Call the binarySearch() method

return binarySearch(data, target, low, mid − 1);

  //Execute the else part


Blurred answer
Students have asked these similar questions
Apply the Binary Search method to find a target using Recursive method.
Using the recursion three method find the upper and lower bounds for the following recur- rence (if they are the same, find the tight bound). T(n) = T(n/2) + 2T(n/3) + n.
By using java, Write a recursive function that finds the maximum element in an array ofintegers, based on comparing the first element in the array against themaximum in the rest of the array recursively.
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
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
Author:Tony Gaddis
Text book image
Digital Fundamentals (11th Edition)
Computer Science
Author:Thomas L. Floyd
Text book image
C How to Program (8th Edition)
Computer Science
Author:Paul J. Deitel, Harvey Deitel
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education