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
A______ is a graphical representation of numeric data.
maks197457 [2]

Answer:

A <u>Chart </u>is a graphical representation of numeric data.

Explanation:

A chart is a type of graphical representation of numerical data that is used to represent different numeric values with the help of quantitative functions. This is used to analyse that numeric data. This is also used to find the relationship between different quantities.

For example if we want to analyze the marks obtained by different students in different courses we can use a chart to show the analysis result in graphical form.

It is the visualization of large numeric data that needs to be analyzed.

7 0
3 years ago
Which statement best describes the purpose of the Insert Function dialog box?
Paladinen [302]

Answer:

It is used to put all types of Excel functions in alphabetical order.

Explanation:

4 0
3 years ago
How many ways are used to insert an image from file?koi h kya​
AnnyKZ [126]

Answer:

Use “Insert” Tab. Method 2: Paste a Picture. Method 3: Drag and Drop. Method 4: Choose "Link to File".

7 0
3 years ago
Which command is not one of the available Change Case options?
valkas [14]

Answer:

there is no option such as small caps available in change case

Explanation:

Change cases in MSword are use to automatic capitalisation rules of text to apply on your document or text.

there are multiple options on Change case such as

  • Sentence case
  • lowercase
  • UPPERCASE
  • Capitalize Each Word.
  • toggle case
5 0
3 years ago
A car holds 16 gallons of gasoline and can travel 312 miles before refueling. Write aC++ program that calculates the number of m
IgorC [24]

Answer:

// here is code in C++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

   // variables Declaration and initialization

   int no_gallon=16;

   int dis=312;

   // find the miles per gallon

   double mile_gallon=dis/double(no_gallon);

   // print the results

   cout<<"number of gallons: "<<no_gallon<<endl;

   cout<<"distance travel before refueling: "<<dis<<endl;

   cout<<"miles per gallon is: "<<mile_gallon<<endl;

return 0;

}

Explanation:

Declare and initialize the number of gallon and distance travel without refueling. Calculate the miles per gallon by dividing distance with number of gallons.Then print the results.

Output:

number of gallons: 16

distance travel before refueling: 312

miles per gallon is: 19.5

6 0
3 years ago
Other questions:
  • The rmdir command (with no options) can only remove empty directories <br> a. True <br> b. False
    14·1 answer
  • ​to prevent intrusions, companies install combinations of hardware and software called _____ to keep unauthorized web users from
    9·1 answer
  • What are the main differences between a workgroup and a domain?
    14·2 answers
  • When you use a script to create all of the tables for a database, you must start with the tables that don't have _______________
    15·1 answer
  • What type of information is kept on a database?
    10·1 answer
  • I need help ASAP please and thank you!
    6·1 answer
  • What was used to enhance silent films of the early 1900s
    15·1 answer
  • Which statements about editing an existing Contact in Outlook are true? Check all that apply.
    9·2 answers
  • How do you customize calendar view​
    9·2 answers
  • ____must cooperate with each other to neutralize the global threat of information censorship. Select 3 options.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!