Autigers.org These questions are from the Exam One of COMP2210-Sp2017 Course at
ID: 3824407 • Letter: A
Question
Autigers.org These questions are from the Exam One of COMP2210-Sp2017 Course at Auburn University. Please Answer them and give a short explanation if necessary. Thanks. www.yifanzhang.cn
Consider a binary search for 33 in the following array: a 9, 18, 28, 32, 34, 39, 39, 45, 62, 72, 76, 98 After two elements have been examined (i.e., compared to 33), what slice of the array remains to be searched? A. 32, 34 B. 9, 18, 28, 32, 34 C. 132, 34, 39, 39, 45, 62] D. 28, 32, 34, 39, 39, 45, 62, 72, 76, 98Explanation / Answer
B) 9, 18,28,32,34 is the slice of array which will be used to search 33.
For binary search to work, first we need to sort the array and find the mid of the array by using
in the given array : low =0 and high will be postion of the last element. i.e high = 11
so mid = 5.5 we will round off to 5
Now the 5th position is having 39 value in our array.
Compare the given number i.e 33 with 39 it means 33 < 39 so we need to go with left most part of mid in our array.
left most part is 9, 18,28,32,34 xso now the element 33 will be search in the given values.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.