Question: Write a binary search method that takes a sorted int [ ] array and an int value to find, and returns the index where the

Write a binary search method that takes a sorted int[] array and an int value to find, and returns the index where the value appears in the array.
For example:
binarySearch(new int[]{1,2,3,4,5,6,7,8},3)
Should return
2
Because 3 appears at index 2 in the array.
If the value does not exist in the array, return -1.
binarySearch(new int[]{1,2,3,4,5,6,7,8},10)
Should return
-1
Your job is to implement the binarySearch method. Your solution should be recursive, so your method should call itself.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!