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
"if" statements are part of creating computer programs, what are these instructions called and how would you use them?
podryga [215]

Answer:

if means that like (if this happen it will come or not come answer)

Explanation:

sorry I don't know how to tell but plz reply if you understand or not.

7 0
2 years ago
Read 2 more answers
Who would be a tippee for purposes of insider trading? a. a janitor who gathers information by reading files on corporate counse
vesna_86 [32]

Answer:

Option A is correct.

Explanation:

A janitor that collects data through reviewing reports on a business counsel's desk could be a tippee for insider trading activities.

Probably, the justification for insider trading remains wrong being that it offers each insider the undue benefit on and around the marketplace, gets the insider's preferences beyond them for which they assume the trustee responsibility, as well as enables the insider to unfairly manipulate the cost of the inventory of a business.

So, the following are the reason the other options are not correct according to the given scenario.

3 0
3 years ago
In Access, you use the Save As command to save a copy of your data. True or False
AveGali [126]

Answer:

false

Explanation:

we use save to save a copy of your data

7 0
2 years ago
Andrew is researching a new operating system for the computers at his workplace. His boss wants the computers to be able to conn
Bumek [7]

Answer:

Windows 8.1 Core

Explanation:

In this particular example, we're going to use Windows 8.1 Core, is the most basic of the window's family, in this case, only we need an OS to connect the hardware with the cloud computing for security and is not necessary another license, in addition, Windows 8.1 core is easiest to use, is so friendly with the user.

6 0
2 years ago
A contracting company recently completed its period of performance on a government contract and would like to destroy all inform
avanturin [10]

Answer:

A. Consult data disposition policies in the contract.

Explanation:

The disposition of data should be carefully handled. The data associated with government project should be handled with care as it may include sensitive information. To destroy the data the company should refer the agreement and see if there is any notes included regarding the data disposition policy. The course of action to destroy the data should be according to the agreement.

5 0
3 years ago
Other questions:
  • At an uncontrolled intersection, you should yield to the car on the right. True or false.
    10·2 answers
  • Write code that inserts userItem into the output string stream itemsOSS until the user enters "Exit". Each item should be follow
    5·1 answer
  • What video game has made the most money as of 2016?
    15·2 answers
  • Write the definition of a method, oddsMatchEvens, whose two parameters are arrays of integers of equal size. The size of each ar
    10·1 answer
  • Before measuring resistance of a component, be sure:
    8·1 answer
  • True or false? Resistors regulate and limit electrical current. A. True B. False
    7·2 answers
  • A desktop computer (named workstation22) can’t connect to the network. A network card was purchased without documentation or dri
    15·1 answer
  • What is the output for the following program?
    6·2 answers
  • WILL GIVE A BRAINLIEST!!! PLS HELP!!!
    5·1 answer
  • I watched an ad but the im button done is no where in sight, has anyone else experienced this recently. it was fine a few days a
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!