# Is there a built-in function to do binary search?

Is there a built-in function to do binary search? Say, given a list (sorted) and a number, find the position which keeps the listed sorted when the number is inserted.

I know that LengthWhile could manage that, but it's slow.

• This might be relevant. See also Mr. W's answer there. – Szabolcs Jan 19 '15 at 16:10

• There is BinarySearch from the Combinatorica package, which is still the function I use most often despite the fact that that package is now deprecated and loading it causes shadowing of some Symbols.
• There is the undocumented GeometricFunctionsBinarySearch` but this function does not appear to perform particularly well.