quicksort : Java Glossary

quicksort
C.A.R. Hoare’s recursive sorting technique. It works with a pivot element, moving all keys smaller than the pivot to one side and all the keys bigger to the other. Then it recursively sorts each half. QuickSort can be pathologically slow if the data are already ordered. In Java, QuickSort is slower than either HeapSort or RadixSort. Typical QuickSort implementations are unstable since they scramble keys to avoid pathological pre-orderings. Free Java source code is available from Roedy Green at Canadian Mind Products.

Oddly, the Haskell version of Quicksort is probably the easiest to understand:

qsort []     = []
qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs)
The first line reads: the result of sorting an empty list ([]) is an empty list.

The second line reads: to sort a list whose first element is x and the rest of which is called xs, sort the elements of xs that are less than x, sort the elements of xs that are greater than or equal to x, and concatenate (++) the results with x sandwiched in the middle.

To learn more about quicksort’s behaviour see Eppstein’s paper. QuickSort source code download..


CMP homejump to top

available on the web at:

http://mindprod.com/jgloss/quicksort.html
  

optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\quicksort.html
logo
Please email your , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email. If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, especially when sending an ad-hominem attack, a rant composed mainly of obscenities or a death threat, please quote the offending passage and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. I can’t very well fix erroneous or ambiguous text if I can’t find it.
Blog
IP:[65.110.21.43]
Your face IP:[107.22.127.92]
You are visitor number 34,399.