1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sergij07 [2.7K]
2 years ago
6

Write a recursive method named binarySearch that accepts a sorted array of integers and an integer target value and uses a recur

sive binary search algorithm to find and return an index at which that target value is found in the array. If the target value is not found in the array, return -1. The following code shows some example calls and their expected return values: // index 0 1 2 3 4 5
Computers and Technology
1 answer:
djyliett [7]2 years ago
6 0

Answer:

10

-1

Process finished with exit code 0

Explanation: see code bellow

public class BinarySearchRecursive {

   public static int binarySearch(int[] a, int key) {

       return binarySearchRecursiveHelper(a, key, 0, a.length - 1);

   }

   public static int binarySearchRecursiveHelper(int[] arr, int target, int start, int end) {

       if (start > end) {

           return -1;

       }

       int mid = (start + end) / 2;

       if (arr[mid] == target) {

           return mid;

       } else if (target < arr[mid]) {

           return binarySearchRecursiveHelper(arr, target, start, mid - 1);

       } else {

           return binarySearchRecursiveHelper(arr, target, mid + 1, end);

       }

   }

   public static void main(String[] args) {

       int[] a = {-4, 2, 7, 10, 15, 20, 22, 25, 30, 36, 42, 50, 56, 68, 85, 92, 103};

       int index = binarySearch(a, 42);   // 10

       System.out.println(index);

       index = binarySearch(a, 66);   // -1

       System.out.println(index);

   }

}

You might be interested in
You have a new phone. What determines what type of messages you can send?
prohojiy [21]
B the services provided by the provider
6 0
2 years ago
If you play gta and don't know the song ''Glamorous'' Then what do you even do when you play?
Paraphin [41]
You literally don’t do anything you’re just like dead of sun
4 0
2 years ago
Read 2 more answers
Which of the following was the name of the first generation of cell phone networks?
coldgirl [10]

Answer:

1G

Explanation:

1 'G' as in first generation.

Hope this helped. :)

3 0
3 years ago
A digital system has been developed to measure temperatures in the range -10˚C to 100˚C. If the accuracy of the system is such t
8090 [49]

If you have 10 bits available then you can interpret any number in range [0,2^{10}-1]=[0,1023].

The system therefore could represent the actual temperature of 39°C.

Hope this helps.

7 0
2 years ago
How do you put a fraction into a computer countulater
ad-work [718]

Answer:

i have no clue sorry:(

Explanation:

I didn't do this to get points i promise

3 0
3 years ago
Read 2 more answers
Other questions:
  • Marys total out of pocket costbwere for the year​
    12·1 answer
  • Dorothy needs to edit JPEG and GIF files in a multimedia application. Which software can Dorothy use to edit these files?
    8·2 answers
  • Ethical design refers to...
    13·1 answer
  • Which is a common problem for inserting pictures into placeholders?
    10·1 answer
  • Able to make a survey form using VB (Visual basics 6.0) to represent ways of conservation of
    8·2 answers
  • You scan the network and find a counterfeit access point that is using the same SSID as an already existing access point. What i
    12·1 answer
  • Create a vector of structures experiments that stores information on subjects used in an experiment. Each struct has four fields
    12·1 answer
  • 30 POINTS FOR THE CORRECT ANSWERS
    12·1 answer
  • A packet switch has 5 users, each offering packets at a rate of 10 packets per second. The average length of the packets is 1,02
    15·1 answer
  • From which os did windows xp evolve?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!