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.
You might also like to view...
A _____ is a computer employed by many users to perform a specific task, such as running network or Internet applications.
A. cache B. register C. server D. bus
Which of the following statements is false?
a. In Java SE 8, an interface may declare default methods—that is, public methods with concrete implementations that specify how an operation should be performed. b. When a class implements an interface, the class receives the interface’s default concrete implementations if it does not override them. c. When you enhance an existing interface with default methods—any class that implemented the original interface will break. d. With default methods, you can declare common method implementations in interfaces (rather than abstract classes), which gives you more flexibility in designing your classes.
What are three tips you should keep in mind before beginning work inside a computer case?
What will be an ideal response?
A situation where a department that does not share information with other departments is a major characteristic of a(n) _______
Fill in the blank(s) with the appropriate word(s).