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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 02:20, eagles2286
The reset circuit used on the four 3-bit counters analyzed in this activity reset the counts to zero (000). it makes sense for the up-counters to start at zero (000), but the down-counters should start at seven (111). what would you need to change so that the 3-bit binary down counter with j/k flip-flops you just created would reset to seven (111)?
Answers: 1
image
Computers and Technology, 22.06.2019 03:10, brylove603
Write a program that begins by reading in a series of positive integers on a single line of input and then computes and prints the product of those integers. integers are accepted and multiplied until the user enters an integer less than 1. this final number is not part of the product. then, the program prints the product. if the first entered number is negative or 0, the program must print “bad input.” and terminate immediately. next, the program determines and prints the prime factorization of the product, listing the factors in increasing order. if a prime number is not a factor of the product, then it must not appear in the factorization. sample runs are given below. note that if the power of a prime is 1, then that 1 must appear in t
Answers: 3
image
Computers and Technology, 22.06.2019 15:00, mitchellk872
Which of the following statements tests if students have a grade of 70 or above, as well as fewer than five absences? a: if(grade > = 70 and daysabsent < = 5): b: if(grade > = 70 or daysabsent < = 5): c: if(grade > 70 and daysabsent < = 5): d: if(grade > 70 or daysabsent < = 5): i took the test the answer is a
Answers: 1
image
Computers and Technology, 22.06.2019 23:00, cchotshot
Is an attack that relies on guessing the isns of tcp packets
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 in other subjects:

Konu
Mathematics, 06.03.2021 04:40