Question: In C++ int binarySearch(int a[], int size, int k) Implement a function that uses binary search to find a given value k in an array
In C++ int binarySearch(int a[], int size, int k)
Implement a function that uses binary search to find a given value k in an array of integers a whose elements are in increasing order. If the value is found, the function returns the index of the value in the array; otherwise it returns -1. For example, for a = (-2, 4, 5, 6, 8) and k = 1, the function returns -1. For k = 5 it returns 2. A declaration of the function is given above. Write your own implementation of binary search; do not use the search function available in the C++ standard library.
Write test code that thoroughly tests your function.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
