subject

Consider the search method (of some class) below which is intended to return the index of the position in array a where key is found. If key is not in the array a, -1 is returned. public int search (int key){
int low=0;
int hight=a. length-1;
while (low<=high){
int mid=(low+high)/2;
int diff=a[mid]-key;
if (diff==0) // a[mid]==key
return mid;
else if (diff<0) //a[mid] low=mid+1;
else
high=mid-1;
}
return -1;
}
private int [ ] a;
Suppose:
a={8, 10, 1, 5, 7, 9, 6, 2}
What value will search return? Why?
8
4
3
-1
No value will be returned. An is thrown.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 07:00
Idon understand these and need some ! ?
Answers: 2
question
Computers and Technology, 24.06.2019 07:00
Why would a business likely use a java applet - to back up their data files for the business - to create a program that a customer can launch in their web browser - to create music on a powerpoint presentation - to organize files on their company directory
Answers: 3
question
Computers and Technology, 24.06.2019 19:00
In python a floating-point number must be written using scientific notation?
Answers: 1
question
Computers and Technology, 25.06.2019 02:30
What are the charges for invasion of privacy on computers
Answers: 1
You know the right answer?
Consider the search method (of some class) below which is intended to return the index of the positi...
Questions
question
Physics, 22.05.2021 06:40
question
Mathematics, 22.05.2021 06:40
question
Mathematics, 22.05.2021 06:40
Questions on the website: 13722363