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]
3 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]3 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
Do you think that dealing with big data demands high ethical regulations, accountability, and responsibility of the person as we
kicyunya [14]

Answer:

i will help you waiting

Explanation:

4 0
3 years ago
What is one way for an entrepreneur to decrease risk?
marysya [2.9K]

Answer

we can  decrease risk for an entrepreneur by creating a team of trusted advisors to rely on.

there are some points that we can take in mind know how  to position our company as a safe position.

revenue streams and additional technology, paving the way for future growth.

Entrepreneurs can use all these  unique strategies to decrease those risk

8 0
3 years ago
What is the value of the variable named result after the following code executes?
Makovka662 [10]

Answer:

The value of result is 20

Explanation:

Given

The above code segment

Required

The value of result

In the first line, we have:

X = 5; Y = 3; Z = 2

In the second, we have:

result = (X + Y)/Z * X

This implies that:

result = (5 + 3)/2 * 5

result = 8/2 * 5

result = 4 * 5

result = 20

3 0
3 years ago
Which of the following is lost when the computer is turned off?
Sergeeva-Olga [200]

Answer:

Memory (RAM) is lost when computer is turned off.

6 0
3 years ago
Give sally sue specific suggestions on how she can improve her powerpoint skills.
castortr0y [4]
Use proper words. Also, add interesting facts about the subject
5 0
3 years ago
Other questions:
  • Why is it important to back up data on a computer before you burn-in test the cpu?
    9·1 answer
  • Create a program asks a user for an odd positive integer. If the user gives and even number or a number that is negative it prom
    7·1 answer
  • Contrast the performance of the three techniques for allocating disk blocks (contiguous, linked, and indexed) for both sequentia
    13·1 answer
  • Which three skills are useful for success in any career?
    8·1 answer
  • The Many–Hands Problem makes it difficult to determine who should be held accountable for mistakes since:
    7·1 answer
  • 6.3 code practice: Question Edhesive
    8·1 answer
  • IPv6 is being developed in order to:
    15·1 answer
  • 4. You are planning to buy a new couch for your family room. Before you leave for the furniture store, you measure the available
    11·1 answer
  • Wendy had been searching the internet for a great deal on jewelry. While looking at one site, a pop-up was displayed that told h
    11·1 answer
  • In a dark place you have only a match , a twig , campfire logs , and oil lamp and a candle which do you literally first /
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!