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 10:30
What can tanya do now to start preparing for the college and scholarship application process? think about her grades, activities in which she can get involved, possible part-time jobs at which she can work, and standardized tests she can take. (10 points) apex
Answers: 2
question
Computers and Technology, 23.06.2019 09:30
Facial expressions and gestures are examples of messages.
Answers: 3
question
Computers and Technology, 23.06.2019 13:00
Which one of the following voltages should never be measured directly with a vom? a. 1200 v b. 500 v c. 800 v d. 100v
Answers: 2
question
Computers and Technology, 24.06.2019 09:10
  to change the number of rows and columns displayed by the excel object a. select the object and drag a size handle on the active object. b. deselect the object and drag a size handle of the object. c. deselect the object and drag a row or column divider of the object. d. select the object and drag a row or column divider on the active object.
Answers: 2
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
Mathematics, 02.11.2020 18:30
question
English, 02.11.2020 18:30
question
Mathematics, 02.11.2020 18:30
question
Social Studies, 02.11.2020 18:30
Questions on the website: 13722367