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
I'm surprised I haven't even got a single warning yet lol
dangina [55]

Answer:

Thats good

Explanation:

Thanks for the points~! ;)

7 0
2 years ago
You can include up to _____ logical conditions in the and function.
Margaret [11]
You can include up to 255 logical conditions in the AND function. This is to test multiple<span> conditions at the same time.
</span><span>The syntax of the AND function is the following: =AND (logical1, [logical2], ...)</span><span>
The AND function can be true (one) and false (null), only one of these two values.
</span><span>The AND function will return #VALUE if no logical values are found or created during evaluation.</span>
5 0
3 years ago
What did Peter and Rosemary do for a living?<br>​
marta [7]

Answer:

Peter and Rosemary Grant are distinguished for their remarkable long-term studies demonstrating evolution in action in Galápagos finches. They have demonstrated how very rapid changes in body and beak size in response to changes in the food supply are driven by natural selection.

Explanation:

please

6 0
3 years ago
Brianna is a multimedia specialist who works for a large fast food chain. What task
Tju [1.3M]

Answer:

Recording and publishing training videos for new employees

Explanation:

Multimedia specialists design and create IT-based multimedia products such as websites, DVDs, and computer games that combine text with sounds, pictures, graphics, video-clips, virtual reality and digital animation

4 0
3 years ago
Why not to use settimeout in angular.
barxatty [35]

Answer:

start with what you know

Explanation:

you can learn alot

4 0
2 years ago
Other questions:
  • What is the rationale behind the development of an operating system in computing?
    15·1 answer
  • A block style business letter is
    14·1 answer
  • While interoperability and unrestricted connectivity is an important trend in networking, the reality is that many diverse syste
    12·1 answer
  • How do you repair a USB?
    15·2 answers
  • FS and GS are two___________________ in protected mode.
    14·1 answer
  • One lap around a standard high-school running track is exactly 0.25 miles. Write a program that takes a number of miles as input
    12·2 answers
  • What data discovery process, whereby objects are categorized into predetermined groups, is used in text mining?
    9·1 answer
  • Use the arr field and mystery () method below.
    9·1 answer
  • Martha is a network monitoring technician working on a firewall for her company’s network. To filter traffic going through the f
    12·2 answers
  • To make the most informed purchasing decision, you should:
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!