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
1.1 what is the osi security architecture? 1.2 what is the difference between passive and active security threats? 1.3 list and
ioda

The well-designed standard architecture for security features in computer networking is defined by the OSI Security Architecture.

The OSI architecture is widely accepted because it establishes the process for ensuring safety in an organization. In a live attack, the victim is made aware of it. The victim of a passive attack is not made aware of the attack. System resources can be modified during an active attack. System resources are not changing while under passive attack. Monitoring a system is the focus of passive assaults, which do not require changing any data on the target system. On the system under attack, active threats will alter data.

Learn more about system here-

brainly.com/question/14253652

#SPJ4

6 0
1 year ago
Write a program that removes all non-alpha characters from the given input. Ex: If the input is: -Hello, 1 world$! the output is
Nuetrik [128]

Answer:

Explanation:

The following code is written in Python. It is a function that takes in a string as a parameter, loops through the string and checks if each character is an alpha char. If it is, then it adds it to an output variable and when it is done looping it prints the output variable. A test case has been provided and the output can be seen in the attached image below.

def checkLetters(str):

   output = ''

   for char in str:

       if char.isalpha() == True:

           output += char

   return output

3 0
3 years ago
In the classic experimental design, there are two groups: the _____ group and the _____ group.
Tju [1.3M]

Main Answer:In the classic experimental design, there are two groups: the <u>treatment group and the control group.</u>

<u>Sub heading:</u>

<u>Explain treatment group and control group?</u>

Explanation:

1.The treatment group also known as the experimental group receives the treatment that the researcher is evaluating.

2.the control group  on the other hand does not receive the treatment.

Reference link:

https://brainly.com

Hashtag:

#SPJ4

5 0
2 years ago
Whenever I go onto Google Chrome, the words are in Spanish! How can I make the words be back in English again? Please let me kno
ivann1987 [24]

Answer:

Go to google setting look up english on setting bar and it should have the option to change or add languages make sure you press save when choosing english

Explanation:

5 0
3 years ago
Online banking tools allow you to pay bills from your computer. <br> a. True<br> b. False
Vaselesa [24]
On your online bank you can add bills from your computer. 
5 0
3 years ago
Read 2 more answers
Other questions:
  • Jenny needs to record the names of 30 students, write down the subjects they studied, and note their grades in each subject afte
    14·2 answers
  • A*+(B+c|3) how do you figure out the coding for this
    14·1 answer
  • I damaged a k12 laptop. do I have to pay for the damage? and if so how much?
    5·1 answer
  • A computer that stores and distributes newsgroup messages is called a newsreader.
    13·1 answer
  • Trish has bought a new computer that she plans to start working on after a week. Since Trish has not used computers in the past,
    10·1 answer
  • The development team recently moved a new application into production for the accounting department. After this occurred, the Ch
    7·1 answer
  • What is the difference between a software engineer and a system analyst?
    8·1 answer
  • What will be the result of running the following code fragment? int year = 0; double rate = 5; double principal = 10000; double
    14·1 answer
  • Try to figure out who the ideal customer is for the IPhone X
    15·2 answers
  • Why is it important to enforce access controls and to keep logs regarding who has access to data closets
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!