{
  "id": "enwiki-001358157912",
  "slug": "sorting-algorithm",
  "title": "Sorting algorithm",
  "qid": "",
  "lead": "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.",
  "body": "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.",
  "categories": [
    "22947425",
    "23118434",
    "23603337",
    "24623845",
    "24745113",
    "24745139",
    "27152323",
    "28269686",
    "48128966",
    "7692542"
  ],
  "license": "CC BY-SA 4.0",
  "source_uri": "https://en.wikipedia.org/w/index.php?oldid=1358157912",
  "content_hash": "",
  "created_at": null,
  "updated_at": 1780781905.0,
  "claims": [],
  "contradictions": [],
  "confidence": 0.6,
  "csl": {
    "id": "enwiki-001358157912",
    "type": "webpage",
    "title": "Sorting algorithm",
    "author": [
      {
        "family": "Anticloud FZ LLE",
        "literal": "Anticloud FZ LLE"
      }
    ],
    "container-title": "encyclopegia.org",
    "publisher": "Anticloud FZ LLE",
    "publisher-place": "Dubai, United Arab Emirates",
    "URL": "https://encyclopegia.org/a/sorting-algorithm",
    "issued": {
      "date-parts": [
        [
          2026,
          11,
          21
        ]
      ]
    },
    "accessed": {
      "date-parts": [
        [
          2026,
          11,
          21
        ]
      ]
    },
    "license": "CC BY-SA 4.0",
    "DOI": "eo1:enwiki-001358157912",
    "isBasedOn": "https://en.wikipedia.org/w/index.php?oldid=1358157912",
    "note": "Immutable snapshot enwiki-001358157912"
  }
}