The binary search algorithm in the text makes recursive 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 left subarray?

a) first, mid – 1
b) first, mid + 1
c) mid – 1, left
d) mid + 1, left
e) left, mid


a) first, mid – 1

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 first and run to index one before mid, namely, mid - 1. 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...

Explain in what ways the execution of each individual SQL statement in a transaction is like a nested subtransaction.

What will be an ideal response?

Computer Science & Information Technology

When content is __________ on another site, it is displayed with formatting that matches the host site and it includes links back to the context in which it was originally posted.

A. repurposed B. encrypted C. embedded D. optimized

Computer Science & Information Technology

A processor has a branch?target buffer. If a branch is in the buffer and it is correctly predicted, there is no branch penalty. The prediction rate is 85% correct. If it is incorrectly predicted, the penalty is 4 cycles. If the branch is not in the buffer, and not taken, the penalty is 2 cycles. Seventy percent of branches are taken. If the branch is not in the buffer and is taken the penalty is 3 cycles. The probability that a branch is in the buffer is 90%. What is the average branch penalty?

What will be an ideal response?

Computer Science & Information Technology

Which of the following is not necessarily an error (either a syntax error or a logic error)?

a) Neglecting to include an action in the body of a while statement that will eventually cause the condition to become false. b) Spelling a key word (such as while or if) with a capitalized first letter. c) Using a condition for a while statement that is initially false. d) An infinite loop.

Computer Science & Information Technology