Category Archives: Selection sort

Another challenge: can you write a correct selection sort?

A month ago today, I posted what’s turned out to be by far the most commented-on article on this site: Are you one of the 10% of programmers who can write a binary search?.  The gist of it was that Jon Bentley, in his book Programming Pearls [], had found in many seminars that when professional programmers are given a high-level description of the binary-search algorithm and a couple of hours to write code that implements it, only one in ten of the offered solutions are free of bugs. An amazing number of you attempted the challenge — somewhere around 500 — and the results seemed to show a correctness rate somewhere between 10% and 50%.

Now we’re going to try the same exercise with one of the simplest of sorting algorithms: selection sort.  (No Wikipedia link for now, because you might see information that you don’t want to see yet.)

Continue reading