e01.org

Sorting algorithm

In computer science, a sorting algorithm is an algorithm that puts elements of a list into an order. The most frequently used orders are numerical order and lexicographical order, and either ascending order or descending order. Efficient sorting is important for optimizing the efficiency of other algorithms (such as search and merge algorithms) that require input data to be in sorted lists. Sorting is also often useful for canonicalizing data and for producing human-readable output. Formally, the output of any sorting algorithm must satisfy two conditions: # The output is in monotonic order (each element is no smaller/larger than the previous element, according to the required order). # The output is a permutation (a reordering, yet retaining all of the original elements) of the input. Although some algorithms are designed for sequential access, the highest-performing algorithms assume data is stored in a data structure which allows random access.

In computer science, a sorting algorithm is an algorithm that puts elements of a list into an order. The most frequently used orders are numerical order and lexicographical order, and either ascending order or descending order. Efficient sorting is important for optimizing the efficiency of other algorithms (such as search and merge algorithms) that require input data to be in sorted lists. Sorting is also often useful for canonicalizing data and for producing human-readable output. Formally, the output of any sorting algorithm must satisfy two conditions: The output is in monotonic order (each element is no smaller/larger than the previous element, according to the required order). The output is a permutation (a reordering, yet retaining all of the original elements) of the input. Although some algorithms are designed for sequential access, the highest-performing algorithms assume data is stored in a data structure which allows random access. One application for stable sorting algorithms is sorting a list using a primary and secondary key. For example, suppose we wish to sort a hand of cards such that the suits are in the order clubs (♣), diamonds ( ♦ ), hearts ( ♥ ), spades (♠), and within each suit, the cards are sorted by rank. This can be done by first sorting the cards by rank (using any sort), and then doing a stable sort by suit: Within each suit, the stable sort preserves the ordering by rank that was already done. This idea can be extended to any number of keys and is utilised by radix sort. The same effect can be achieved with an unstable sort by using a lexicographic key comparison, which, e.g., compares first by suit, and then compares by rank if the suits are the same. ===Table of running times of popular algorithms=== In Algorithms and Data Structures Niklaus Wirth gives a comparison of the running time of several of the popular algorithms on the Lilith computer. 15 Sorting Algorithms in 6 Minutes (Youtube) – Visualization and "audibilization" of 15 Sorting Algorithms in 6 Minutes. A036604 sequence in OEIS database titled "Sorting numbers: minimal number of comparisons needed to sort n elements" – Performed by Ford–Johnson algorithm. Sorting Algorithms Used on Famous Paintings (Youtube) – Visualization of Sorting Algorithms on Many Famous Paintings. A Comparison of Sorting Algorithms – Runs a series of tests of 9 of the main sorting algorithms using Python timeit and Google Colab.

References

  1. ^ Nilsson, Stefan (2000). "The Fastest Sorting Algorithm?" . Dr. Dobb's . Archived from the original on 2019-06-08 . Retrieved 2015-11-23 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1448233200.0
  2. ^ Andersson, Arne; Hagerup, Torben; Nilsson, Stefan; Raman, Rajeev (1995). "Sorting in linear time?". Proceedings of the twenty-seventh annual ACM symposium on Theory of computing . ACM. pp. 427– 436. Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  3. ^ Han, Yijie; Thorup, M. (2002). Integer sorting in O(n√(log log n)) expected time and linear space . The 43rd Annual IEEE Symposium on Foundations of Computer Science . pp. 135– 144. doi : 10.1109/SFCS.2002.1181890 . ISBN 0-7695-1822-2 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  4. ^ Wirth, Niklaus (1986). Algorithms & Data Structures . Upper Saddle River, NJ: Prentice-Hall. pp. 76– 77. ISBN 978-0130220059 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  5. ^ Wirth 1986 , pp. 79–80 Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  6. ^ Wirth 1986 , pp. 101–102 Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  7. ^ "Tim Peters's original description of timsort" . python.org . Archived from the original on 22 January 2018 . Retrieved 14 April 2018 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  8. ^ "OpenJDK's TimSort.java" . java.net . Archived from the original on 14 August 2011 . Retrieved 14 April 2018 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  9. ^ "sort – perldoc.perl.org" . perldoc.perl.org . Archived from the original on 14 April 2018 . Retrieved 14 April 2018 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  10. ^ Wirth 1986 , pp. 87–89 Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  11. ^ Wirth 1986 , p. 93 Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  12. ^ Cormen, Thomas H. ; Leiserson, Charles E. ; Rivest, Ronald L. ; Stein, Clifford (2009), Introduction to Algorithms (3rd ed.), Cambridge, MA: The MIT Press, pp. 171– 172, ISBN 978-0262033848 Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  13. ^ Musser, David R. (1997), "Introspective Sorting and Selection Algorithms", Software: Practice and Experience , 27 (8): 983– 993, doi : 10.1002/(SICI)1097-024X(199708)27:8<983::AID-SPE117>3.0.CO;2-# Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  14. ^ Wirth 1986 , pp. 81–82 Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  15. ^ Demuth, Howard B. (1956). Electronic Data Sorting (PhD thesis). Stanford University. ProQuest 301940891 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  16. ^ "tag sort Definition from PC Magazine Encyclopedia" . Pcmag.com . Archived from the original on 6 October 2012 . Retrieved 14 April 2018 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  17. ^ Donald Knuth , The Art of Computer Programming , Volume 3: Sorting and Searching , Second Edition. Addison-Wesley, 1998, ISBN 0-201-89685-0 , Section 5.4: External Sorting, pp. 248–379. Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  18. ^ Ellis Horowitz and Sartaj Sahni , Fundamentals of Data Structures , H. Freeman & Co., ISBN 0-7167-8042-9 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  19. ^ Bai, Xingjian; Coester, Christian (2023). Sorting with Predictions . NeurIPS. p. 5. Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  20. ^ Cormen, Thomas H. ; Leiserson, Charles E. ; Rivest, Ronald L. ; Stein, Clifford (2009), "8", Introduction To Algorithms (3rd ed.), Cambridge, MA: The MIT Press, p. 167, ISBN 978-0-262-03293-3 Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  21. ^ Ajtai, M. ; Komlós, J. ; Szemerédi, E. (1983). An O(n log n) sorting network . STOC '83. Proceedings of the fifteenth annual ACM symposium on Theory of computing . pp. 1– 9. doi : 10.1145/800061.808726 . ISBN 0-89791-099-0 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  22. ^ Kim, P. S.; Kutzner, A. (2008). Ratio Based Stable In-Place Merging . TAMC 2008. Theory and Applications of Models of Computation . LNCS . Vol. 4978. pp. 246– 257. CiteSeerX 10.1.1.330.2641 . doi : 10.1007/978-3-540-79228-4_22 . ISBN 978-3-540-79227-7 . {{ cite conference }} : Cite uses deprecated parameter |citeseerx= ( help ) Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  23. ^ Sedgewick, Robert (1 September 1998). Algorithms In C: Fundamentals, Data Structures, Sorting, Searching, Parts 1-4 (3 ed.). Pearson Education. ISBN 978-81-317-1291-7 . Retrieved 27 November 2012 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  24. ^ Cormen, Thomas H. ; Leiserson, Charles E. ; Rivest, Ronald L. ; Stein, Clifford (2001), "8", Introduction To Algorithms (2nd ed.), Cambridge, MA: The MIT Press, p. 165, ISBN 0-262-03293-7 Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  25. ^ a b Thorup, M. (February 2002). "Randomized Sorting in O(n log log n) Time and Linear Space Using Addition, Shift, and Bit-wise Boolean Operations". Journal of Algorithms . 42 (2): 205– 230. doi : 10.1006/jagm.2002.1211 . S2CID 9700543 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  26. ^ Brejová, B. (15 September 2001). "Analyzing variants of Shellsort". Inf. Process. Lett. 79 (5): 223– 227. doi : 10.1016/S0020-0190(00)00223-4 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  27. ^ Wirth 1986 , p. 100. Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  28. ^ Gruber, H.; Holzer, M.; Ruepp, O. (2007), "Sorting the slow way: an analysis of perversely awful randomized sorting algorithms", 4th International Conference on Fun with Algorithms, Castiglioncello, Italy, 2007 (PDF) , Lecture Notes in Computer Science, vol. 4475, Springer-Verlag, pp. 183– 197, doi : 10.1007/978-3-540-72914-3_17 , ISBN 978-3-540-72913-6 , archived (PDF) from the original on 2020-09-29 , retrieved 2020-06-27 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1593212400.0
  29. ^ Lohr, Steve (Dec 17, 2001). "Frances E. Holberton, 84, Early Computer Programmer" . NYTimes. Archived from the original on 16 December 2014 . Retrieved 16 December 2014 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  30. ^ Shell, D. L. (1959). "A High-Speed Sorting Procedure" (PDF) . Communications of the ACM . 2 (7): 30– 32. doi : 10.1145/368370.368387 . S2CID 28572656 . Archived from the original (PDF) on 2017-08-30 . Retrieved 2020-03-23 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1584918000.0
  31. ^ a b c Cormen, Thomas H. ; Leiserson, Charles E. ; Rivest, Ronald L. ; Stein, Clifford (2001) [1990]. Introduction to Algorithms (2nd ed.). MIT Press and McGraw-Hill. ISBN 0-262-03293-7 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  32. ^ a b Goodrich, Michael T. ; Tamassia, Roberto (2002). "4.5 Bucket-Sort and Radix-Sort". Algorithm Design: Foundations, Analysis, and Internet Examples . John Wiley & Sons. pp. 241– 243. ISBN 978-0-471-38365-9 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  33. ^ Merge sort in Java 1.3 , Sun. Archived 2009-03-04 at the Wayback Machine Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  34. ^ "Meet the 'Refrigerator Ladies' Who Programmed the ENIAC" . Mental Floss . 2013-10-13. Archived from the original on 2018-10-08 . Retrieved 2016-06-16 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1466031600.0
  35. ^ Sedgewick, R. (1978). "Implementing Quicksort programs". Comm. ACM . 21 (10): 847– 857. doi : 10.1145/359619.359631 . S2CID 10020756 . Wikipedia revision 1358157912, retrieved 2026-11-21 · 1795215600.0
  36. Meet the 'Refrigerator Ladies' Who Programmed the ENIAC . · 1780700400.0
  37. [http://java.sun.com/j2se/1.3/docs/api/java/util/Arrays.html#sort(java.lang.Object%5B%5D) Merge sort in Java 1.3], Sun. Webarchive|url=https://web.archive.org/web/20090304021927/http://java.sun.com/ . · 1780700400.0
  38. A High-Speed Sorting Procedure . · 1780700400.0
  39. tag sort Definition from PC Magazine Encyclopedia . Pcmag.com . retrieved 14 April 2018 · 1780700400.0
  40. Sorting with Predictions . · 1780700400.0
  41. Lohr, Steve. Frances E. Holberton, 84, Early Computer Programmer . · 1780700400.0
  42. citation |last1=Cormen |first1=Thomas H. |author1-link=Thomas H. Cormen |last2=Leiserson |first2=Charles E. |author2-link=Charles E. Leiserson |last3=Rivest |first3=Ronald L. |author3-link=Ron Rives . · 1780700400.0
  43. Sedgewick, Robert. Algorithms In C: Fundamentals, Data Structures, Sorting, Searching, Parts 1-4 . · 1780700400.0
  44. Nilsson, Stefan. The Fastest Sorting Algorithm? . 2000. · 1780700400.0
  45. - align="center" | Radix sort#Least significant digit|LSD Radix Sort |style="background:#dfd"| n \cdot \frac{k}{d} |style="background:#dfd"| n \cdot \frac{k}{d} |style="background:#dfd"| n \cdot . · 1780700400.0
  46. Tim Peters's original description of timsort . python.org . retrieved 14 April 2018 · 1780700400.0
  47. OpenJDK's TimSort.java . java.net . retrieved 14 April 201 · 1780700400.0
  48. sort – perldoc.perl.org . perldoc.perl.org . retrieved 14 April 2018 · 1780700400.0
source: e01 Encyclopedia · licence: CC BY-SA 4.0 · page · source revision

Cite this

"Sorting algorithm". 1780781905. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1358157912

JSON record · API collection · citation policy