Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What XXX will generate the following output? Enter a value: 0 was not found. public class BinarySearch { public static int binarySearch ( int [

What XXX will generate the following output? Enter a value: 0 was not found.
public class BinarySearch {
public static int binarySearch(int [] list, int listSize, int key){
int mid;
int low;
int high;
low =0;
high = listSize -1;
while (high >= low){
mid =(high + low)/2;
if (list[mid]< key){
low = mid +1;
}
else if (list[mid]> key){
high = mid -1;
}
else {
return XXX;
}
}
return -1;
}
public static void main(String [] args){
Scanner scnr = new Scanner(System.in);
int [] list ={2,4,7,10,11,32,45,87};
final int listSize =8;
int i;
int key;
int keyIndex;
System.out.print("Enter a value: ");
key = scnr.nextInt();
keyIndex = binarySearch(list, listSize, key);
if (keyIndex ==-1){
System.out.println(key +" was not found.");
}
else {
System.out.println("Found "+ key +" at index "+ keyIndex +".");
}
}
}
a.
low
b.
mid
c.
high
d.
-1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Fundamentals Concepts, Drivers & Techniques

Authors: Thomas Erl, Wajid Khattak, Paul Buhler

1st Edition

0134291204, 9780134291208

Students also viewed these Databases questions

Question

=+What action steps will you take to handle this situation?

Answered: 1 week ago