Talk:Binary search (C)

From LiteratePrograms

Jump to: navigation, search

I believe if there are multiple copies of the same item, this algorithm is undefined which copy is returned. It should probably step backwards from the one which was found in order to return the index of the first occurance (taking care not to access data before the start of the array).

The issue of duplicate data values is not a problem if all that is wanted is to know whether a value is present or not.

In many practical uses of a binary search, you also want to return an index into the data for the adjacent (higher or lower?) value, if the requested value was not found.

Personal tools