This is an old version, saved 5 Dec 2026, 04:28 by TechWritereditor. See the current version.

Quicksort

Quicksort is an algorithm for putting a list of items, such as numbers or words, into order. It was invented by the British computer scientist Tony Hoare and published in July 1961, and it is still regarded as one of the best sorting algorithms, with implementations in many programming languages and libraries.[1]

Contents
  1. History
  2. How it works
  3. See also
  4. References

History

Hoare thought of the algorithm in 1959 while studying the machine translation of languages at Moscow State University.[2][3] A Russian-to-English translation system stored its dictionary on magnetic tape, so the words of a sentence had to be sorted into alphabetical order before they could be looked up.[4] Hoare's first idea took time proportional to the square of the sentence length; quicksort was his second, better idea.[4] He could not express it in Mercury Autocode, the only language he then knew, but on a course in ALGOL 60, a language that supported recursion, he realised that recursion made the algorithm easy to write.[4][5] Hoare received the ACM Turing Award in 1980 for his contributions to programming language design.[5]

How it works

Quicksort is a "divide and conquer" method. It picks one element, called the pivot, and splits the remaining items into those smaller than the pivot and those larger. The same steps are then applied to each part in turn until every part has one or no elements, at which point the whole list is sorted.[4] In Hoare's partitioning scheme, one pointer moves up from the bottom of the list and another down from the top; when they find items on the wrong side they swap them, until the pointers cross.[4]

The algorithm sorts in place, needing little extra memory, but it is not stable, meaning equal items may not keep their original order.[4] On average it takes time proportional to n log n for n items, but a poor choice of pivot, for example always using the first item of a list that is already sorted, can make it as slow as n².[4]

See also

References

  1. ^ Happy birthday Quicksort!. Plus Magazine, University of Cambridge. 2021-06-04. plus.maths.org
  2. ^ Sir Antony Hoare. Computer History Museum. computerhistory.org
  3. ^ Tony Hoare. Encyclopaedia Britannica. britannica.com
  4. ^ Quicksort. Stanford University. cs.stanford.edu
  5. ^ C. Antony R. Hoare. Association for Computing Machinery. amturing.acm.org