Page 469 - AP Computer Science A, 7th edition
P. 469

{
int low = 0;
int high = a.length – 1; while (low <= high)
{
int mid = (low + high) / 2; if (a[mid] == key)
return mid;
else if (a[mid] < key)
low = mid + 1; else
high = mid – 1; }
return –1; }
A binary search will be performed on the following list.
a[0] a[1] a[2] a[3] a[4] a[5]
4 7 9 11 20 24
10. To find the key value 27, the search interval after the first pass through the while loop will be
(A) a[0] ... a[7] (B) a[5] ... a[6] (C) a[4] ... a[7] (D) a[2] ... a[6] (E) a[6] ... a[7]
11. How many iterations will be required to determine that 27 is not in the list?
(A) 1
(B) 3
(C) 8
(D) 27
(E) An infinite loop since 27 is not found














































































   467   468   469   470   471