The binary search algorithm in the text makes recursive calls on subarrays of the array passed to the algorithm. The range passed to the search function is first to last. The search algorithm makes recursive calls on the left or right subarray that target will be in, if the target is present. What are the left and right ends of the right subarray?

a) Last , mid – 1
b) last , mid + 1
c) mid – 1, last
d) mid + 1, last
e) last, mid

d) mid + 1, last

The middle element has been eliminated by the following code fragment that occurs before the recursive calls:
```
if(key == a[mid])
{
found = true; location = mid;
}
```
The range will start with index one after mid, namely, mid + 1 and run to the index last. The rest of the answers have off-by-one errors, or they get the range backwards, or both.

Computer Science & Information Technology

You might also like to view...

Which of the following correctly represents the expression a = a + 3?

a) 3a b) a += 3 c) a + 3 d) None of the above.

Computer Science & Information Technology

In terms of information systems, issues of privacy relate to the collection and use or misuse of _____.?

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology