Merge sort

Merge sort
An example of merge sort. First, divide the list into the smallest unit (1 element), then compare each element with the adjacent list to sort and merge the two adjacent lists. Finally, all the elements are sorted and merged.
ClassSorting algorithm
Data structureArray
Worst-case performance
Best-case performance typical, natural variant
Average performance
Worst-case space complexity total with auxiliary, auxiliary with linked lists[1]

In computer science, merge sort (also commonly spelled as mergesort and as merge-sort[2]) is an efficient, general-purpose, and comparison-based sorting algorithm. Most implementations produce a stable sort, which means that the relative order of equal elements is the same in the input and output. Merge sort is a divide-and-conquer algorithm that was invented by John von Neumann in 1945.[3] A detailed description and analysis of bottom-up merge sort appeared in a report by Goldstine and von Neumann as early as 1948.[4]

  1. ^ Skiena (2008, p. 122)
  2. ^ Goodrich, Michael T.; Tamassia, Roberto; Goldwasser, Michael H. (2013). "Chapter 12 - Sorting and Selection". Data structures and algorithms in Python (1st ed.). Hoboken [NJ]: Wiley. pp. 538–549. ISBN 978-1-118-29027-9.
  3. ^ Knuth (1998, p. 158)
  4. ^ Katajainen, Jyrki; Träff, Jesper Larsson (March 1997). "Algorithms and Complexity". Proceedings of the 3rd Italian Conference on Algorithms and Complexity. Italian Conference on Algorithms and Complexity. Lecture Notes in Computer Science. Vol. 1203. Rome. pp. 217–228. CiteSeerX 10.1.1.86.3154. doi:10.1007/3-540-62592-5_74. ISBN 978-3-540-62592-6.