[Tutor] Binary search question

Alan Gauld alan.gauld at btinternet.com
Fri Apr 23 23:07:11 CEST 2010


"Hugo Arts" <hugo.yoshi at gmail.com> wrote
> A binary search requires data to be sorted, but works in O(log n), so
> It will always be faster than a naive linear search like the in
> operator performs.

Being picky but 'in' could be faster if the item searched for happens 
to be very near the front of the list. "Always" is a strong word :-)

But in general terms you are, of course, quite right, a linear search 
is slower than a chop for sorted data.

Alan G



More information about the Tutor mailing list