[Tutor] binary vs. linear search
alan.gauld@bt.com
alan.gauld@bt.com
Mon, 26 Aug 2002 13:32:19 +0100
> 6,175 times is signficant. Duh. As long as I make sure I pass a sorted
> list to the function, the performance gain over the regular linear
> search is impressive to say the least.
How does it compare with a list comprehension or filter:
sixes = filter(lambda w: len(w) == 6, wordlist)
Should pull out the six letter words without sorting.
Then sorting sixes and using the binary search on that
list to find the specific word should be fast. The
combined approach should be faster than using binary
search for both functions (I suspect)?
Alan g.