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 11:00
Eva has many contacts on the professional networking site she uses which contacts are considered second degree
Answers: 3
question
Computers and Technology, 22.06.2019 22:20
Avariable of the data type arrays is storing 10 quantities. what is true about these quantities? a. the quantities all have different characteristics. b. the quantities all have the same characteristics. c. five quantities have the same and five have different characteristics. d. it is necessary for all quantities to be integers. e. it is necessary for all quantities to be characters.
Answers: 2
question
Computers and Technology, 23.06.2019 03:30
In vista and windows 7, the appearance and personalization option allows you to change the
Answers: 1
question
Computers and Technology, 23.06.2019 19:00
Now you’re on your own. include a short summary of this section with plots in your lab report. write a matlab script file to do steps (a) through (d) below. include a listing of the script file with your report. 1 the soundsc(xx,fs) function requires two arguments: the first one (xx) contains the vector of data to be played, the second argument (fs) is the sampling rate for playing the samples. in addition, soundsc(xx,fs) does automatic scaling and then calls sound(xx,fs) to actually play the signal. mcclellan, schafer, and yoder, dsp first, 2e, isbn 0-13-065562-7. prentice hall, upper saddle river, nj 07458. c 2015 pearson education, inc. 4 mcclellan, schafer and yoder, signal processing first. prentice hall, upper saddle river, new jersey, 2003. c 2003 prentice hall. (a) generate a time vector (tt) to cover a range of t that will exhibit approximately two cycles of the 4000 hz sinusoids defined in the next part, part (b). use a definition for tt similar to part 2.2(d). if we use t to denote the period of the sinusoids, define the starting time of the vector tt to be equal to t , and the ending time as ct . then the two cycles will include t d 0. finally, make sure that you have at least 25 samples per period of the sinusoidal wave. in other words, when you use the colon operator to define the time vector, make the increment small enough to generate 25 samples per period. (b) generate two 4000 hz sinusoids with arbitrary amplitude and time-shift. x1.t / d a1 cos.2
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
Mathematics, 15.04.2021 23:30
question
History, 15.04.2021 23:30
question
History, 15.04.2021 23:30
question
Chemistry, 15.04.2021 23:30
question
Mathematics, 15.04.2021 23:30
Questions on the website: 13722363