The Reinvigorated Programmer (Mike Taylor) quotes from Jon Bentley’s 1986 classic Programming Pearls:
Only 10% of programmers can write a binary search
Better yet, he has a coding challenge for you to take part in (post answers as comments):
Here are the rules:
- Use whatever programming language you like.
- No cutting, pasting or otherwise copying code. Don’t even look at other binary search code until you’re done.
- I need hardly say, no calling bsearch(), or otherwise cheating :-)
- Take as long as you like — you might finish, and feel confident in your code, after five minutes; or you’re welcome to take eight hours if you want (if you have the time to spare).
- You’re allowed to use your compiler to shake out mechanical bugs such as syntax errors or failure to initialise variables, but …
- NO TESTING until after you’ve decided your program is correct.
- Finally, the most important one: if you decide to begin this exercise, then you must report — either to say that you succeeded, failed or abandoned the attempt. Otherwise the figures will be skewed towards success.
If you haven’t yet, try it. Read just the article, but do not look at the others’ comments just yet.
After you have attempted this, there is his redux, on why coding exercises like this matter; and his redux of the redux, on why you should not test while attempting exercises like this. They are all worth a good read.
Copyright © 2008-present Brendan Graetz