You are viewing a single comment's thread from:

RE: Python Tricks #14 - Binary search is faster than linear

You could make it even a little faster by using the return True statement instead of done = True and remove done from the program by writing return False at the end. That way you don't need to test and not done every loop.

Also I think you meant to use last = mid-1 and
first = mid+1. Otherwise your program would be linear.

Sort:  

Thanks for your notes! Indeed it is more pytonic without done variable. I made corrections according to your suggestions. Thanks!

Coin Marketplace

STEEM 0.04
TRX 0.32
JST 0.082
BTC 60713.70
ETH 1556.06
USDT 1.00
SBD 0.50