Lab #6 Section 1 – Chapter 11 Write a program class called BinarySearch that has a static method called Search that searches the array a for key. If key is not in the array segment, then -1 is...

1 answer below »
pdf programming


Lab #6 Section 1 – Chapter 11 Write a program class called BinarySearch that has a static method called Search that searches the array a for key. If key is not in the array segment, then -1 is returned. Otherwise returns an index in the segment such that key == a[index]. Precondition: a[first] <= a[first="" +=""><= ...=""><= a[last]. the search method takes an int array, index of first number in array, index of last number in array and key to search for in the array. section 2 – chapter 12 write a main program that uses the binarysearch class you created in section 1 to search for a value. your program will print key + " is at index " + result) if it finds the value or key + " is not in the array” if it does not find the value. a[last].="" the="" search="" method="" takes="" an="" int="" array,="" index="" of="" first="" number="" in="" array,="" index="" of="" last="" number="" in="" array="" and="" key="" to="" search="" for="" in="" the="" array.="" section="" 2="" –="" chapter="" 12="" write="" a="" main="" program="" that="" uses="" the="" binarysearch="" class="" you="" created="" in="" section="" 1="" to="" search="" for="" a="" value.="" your="" program="" will="" print="" key="" +="" "="" is="" at="" index="" "="" +="" result)="" if="" it="" finds="" the="" value="" or="" key="" +="" "="" is="" not="" in="" the="" array”="" if="" it="" does="" not="" find="" the="">
Answered Same DayNov 08, 2021

Answer To: Lab #6 Section 1 – Chapter 11 Write a program class called BinarySearch that has a static method...

Neha answered on Nov 09 2021
155 Votes
import java.util.Arrays;
import java.util.Scanner;
public class Main{
public static int bin
arySearch(int arr[], int first, int last, int key){
if (last>=first){
int mid = first + (last - first)/2;
if (arr[mid] == key){
return mid;
}
if (arr[mid] > key){
return binarySearch(arr, first, mid-1, key);//search in left subarray
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here