Question
bool binarySearch(int a[], int size, int k); Write a function called binarySearch that finds an occurrence of an integer k in an array a using
bool binarySearch(int a[], int size, int k);
Write a function called binarySearch that finds an occurrence of an integer k in an array a using binary search. The function signature is given above. Write your own implementation of binary search; do not use the search function available in the C++ standard library. Binary search assumes that the sequence of values (stored in an array in our case) is either non-decreasing or non-increasing. Assume that the array passed into binarySearch is non-decreasing, which means that each value beyond the first is either equal to or greater than the previous value. Binary search is a natural search technique when the collection of items is stored in order. It is roughly the technique you would use to look up the meaning of a word in a dictionary or find a phone number in a telephone book. Write test code that thoroughly tests your function. Express your tests using assertions.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started