in reply to Re: Binary search algorithm.
in thread Binary search algorithm.

And finally, why don't you just use grep? At least with your trivial example, it is significantly faster.

You are comparing apples to oranges.

grep is always O( N ) and will work whether the data is sorted or not.

Binary Search has a best case of O( 1 ) and a worst case of O( log N ) and will only work if the data is sorted.

Replies are listed 'Best First'.
Re^3: Binary search algorithm.
by ikegami (Patriarch) on Aug 13, 2011 at 06:00 UTC

    Actually, you are. The formula you are giving says how the speed of the algorithms *scale*, whereas afoken was talking about how fast they are.

    Although you do bring up a good point: afoken only measured the worst case.