Department of Mathematics & Computer Science - York College - CUNY
Fall 2018: CS 291 - Computer Science II
11. [6 points] Write code statements to complete the binary search function. The function returns the
index of the integer in the array when found, if not found it will return -1.
int binarySearchRecursion(vector<int> v, int x, int start, int end) {
if (start > end) return -1;
int mid = _________; //find the mid point
if (x == v[mid]) return _________;
if (x > v[mid])
return binarySearchRecursion(v, x, _________, _________);
else // i.e. x < v[mid]
return binarySearchRecursion(v, x, _________, _________);
}
12. [3 points] Name one precondition/prerequisite of a binary search.