Story Behind World's Fastest Sorting Algorithm - Quick Sort

Story Behind World's Fastest Sorting Algorithm - Quick Sort

10 January, 2021

We all know that the fastest sorting algorithm is Quick Sort. But do you know how this algorithm was born? IF NOT SPARE FEW MINUTES AND READ THE AMAZING STORY BEHIND IT.

The quicksort algorithm was developed in 1959 byTony Hoarewhile he was a visiting student atMoscow State University. At that time, Hoare was working on amachine translationproject for theNational Physical Laboratory.

As a part of the translation process, he needed to sort the words in Russian sentences before looking them up in a Russian-English dictionary, which was in alphabetical order onmagnetic tape.

After recognizing that his first idea,insertion sort, would be slow, he came up with a new idea. He wrote the partition part in MercuryAutocode but had trouble dealing with the list of unsorted segments. On return to England, he was asked to write code for Shell sort.

Hoare mentioned to his boss that he knew of a faster algorithm and his boss bet sixpence that he did not. His boss ultimately accepted that he had lost the bet. Later, Hoare learned aboutALGOLand its ability to do recursion that enabled him to publish the code inCommunications of the Association for Computing Machinery, the premier computer science journal of the time.

Quicksort gained widespread adoption, appearing, for example, inUnixas the default library sort subroutine. Hence, it lent its name to theC standard librarysubroutineqsortand in the reference implementation ofJava.

Robert Sedgewick's Ph.D. thesis in 1975 is considered a milestone in the study of Quicksort where he resolved many open problems related to the analysis of various pivot selection schemes including Samplesort, adaptive partitioning by Van Emden as well as the derivation of the expected number of comparisons and swaps.Jon BentleyandDoug McIlroyincorporated various improvements for use in programming libraries, including a technique to deal with equal elements and a pivot scheme known aspseudomedian of nine,where a sample of nine elements is divided into groups of three and then the median of the three medians from three groups is chosen.

Bentley described another simpler and compact partitioning scheme in his bookProgramming Pearlsthat he attributed to Nico Lomuto. Later Bentley wrote that he used Hoare's version for years but never really understood it but Lomuto's version was simple enough to prove correct.

Bentley described Quicksort as the "most beautiful code I had ever written" in the same essay. Lomuto's partition scheme was also popularized by the textbookIntroduction to Algorithmsalthough it is inferior to Hoare's scheme because it does three times more swaps on average and degrades toO(n2) runtime when all elements are equal.

In 2009, Vladimir Yaroslavskiy proposed a new Quicksort implementation using two pivots instead of one.In the Java core library mailing lists, he initiated a discussion claiming his new algorithm to be superior to the runtime library's sorting method, which was at that time based on the widely used and carefully tuned variant of classic Quicksort by Bentley and McIlroy. Yaroslavskiy's Quicksort has been chosen as the new default sorting algorithm in Oracle's Java 7 runtime libraryafter extensive empirical performance tests.

So that was all about history, if you want to know more about something else, drop a comment.