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
What type of elements are bridges exposed to yearly
Anvisha [2.4K]
the answer would be ship collision
7 0
3 years ago
Read 2 more answers
Which statement is true about the elements of the interface of a presentation program? The status bar appears at the top of the
Lemur [1.5K]
The first one, "The status bar appears at the top of the page and displays options to style your slides."

3 0
2 years ago
Read 2 more answers
What can be entered in a search box to find data? data size a name relevance purpose
horrorfan [7]
Yes it can bc revleance
4 0
3 years ago
Read 2 more answers
g Define memory hierarchy. A. The rate at which information can be transferred from one place to another. B. Ordering storage sy
andrew-mc [135]

Answer:

The correct option is B.

Explanation:

Memory hierarchy is the ordering of storage systems according to their speed, capacity and cost.

The hierarchy consist of Register as the top, followed by cache, then main memory, secondary memory and external storage. As you go down the hierarchy, the speed decreases, the size increases and the cost decreases also.

Memory hierarchy diagram is attached for reference.

3 0
3 years ago
Jeffrey works with a huge database of spreadsheet records each day. To organize and identify these spreadsheets, he wants to ass
mariarad [96]

Answer:

A. Document Properties

B. Permission

C. Document Options

D. File Details

The answer to this question is "File Details " . This will help Jeffrey works efficiently with a huge database of spreadsheet records each day. He can assign names to these File Details which represents each spreadsheet records. This will help his report more organized and easy to identity.

8 0
3 years ago
Other questions:
  • What is the term for the process of gathering information through images taken at a distance?
    13·1 answer
  • Easy question how the internet has impacted y’all life
    13·1 answer
  • How many times do you usually use npm?<br> Put your answer in the box.
    6·1 answer
  • Most graphics software uses a process called pixel _________ to create new pixels by averaging the colors of nearby pixels.â
    6·1 answer
  • When a formula contains the address of a cell, it is called a(n) ________.
    15·1 answer
  • Why are computers useful for modeling situations?
    13·2 answers
  • A firm offers virtual local area networks and firewalls as an on-demand cloud service. Which service does the firm offer?
    11·2 answers
  • Select the correct answer.
    15·2 answers
  • Write a program that accepts the lengths of three sides of a triangle as an input from the user: A, B, C
    13·1 answer
  • How do you get off of the comments after you look at them wit out going all the way off the app?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!