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.
In reply to Re^2: Binary search algorithm.
by jwkrahn
in thread Binary search algorithm.
by kindlychung
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |