Question: Modify BinarySearch (Program 4.2.3) so that if the search key is in the array, it returns the smallest index (i) for which (a[i]) is equal

Modify BinarySearch (Program 4.2.3) so that if the search key is in the array, it returns the smallest index \(i\) for which \(a[i]\) is equal to key, and otherwise returns \(-i\), where \(i\) is the smallest index such that \(a[i]\) is greater than key.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Algorithm Design Questions!