News for hackers. Stuff that matters.
Re:Are you one of the 10% of programmers who can write a bin... by barrkel on Monday April 19, 2010 @04:30PM (#1277761)
The trick with this binary search test isn't knowing or being taught or learning the algorithm, or finding it difficult; it's making sure you find and deal with every corner case, first time, without testing. For example: is an empty array handled properly? An array with duplicates? Is every item, including first and last, found correctly? What about arrays with an even number of elements vs odd, vs power of two? How about an array with over 1 billion elements (the integer overflow problem)? Are values before and after the sorted range indicated properly? If working with duplicates, do you want a found index at the start of the range, or at the end?

You get the picture.

Re:Are you one of the 10% of programmers who can write a bin... by waterlesscloud on Monday April 19, 2010 @04:34PM (#1277776)
So what this is really all about is this- do you mentally step through your code and consider what could go wrong at each step?
Re:Are you one of the 10% of programmers who can write a bin... by barrkel on Monday April 19, 2010 @05:36PM (#1277917)
I would rather think in invariants - knowing what must be true at particular points in the code, at the start of loop bodies, etc. Essentially, doing a proof in one's head.