{
  "schema_version": "1.0",
  "codex": "thecodex.expert/coding",
  "type": "algorithm",
  "slug": "algorithms/sorting",
  "name": "Sorting Algorithms",
  "section": "Algorithms",
  "canonical_definition": "Sorting algorithms arrange a sequence of elements into a defined order. Comparison sorts are provably bounded below by Omega(n log n) comparisons in the worst case. Non-comparison sorts (counting, radix, bucket) can achieve O(n) by exploiting the structure of the keys.",
  "complexity": {
    "comparison_lower_bound": "Omega(n log n)",
    "merge_sort_all_cases": "Theta(n log n)",
    "quicksort_average": "Theta(n log n)",
    "quicksort_worst": "Theta(n^2)",
    "counting_sort": "O(n+k)"
  },
  "confidence": "high",
  "last_verified": "2026-06-01",
  "url": "https://thecodex.expert/coding/algorithms/sorting/",
  "concept_relationship": {
    "requires_first": [
      "algorithms/complexity",
      "data-structures/arrays"
    ],
    "enables": [
      "algorithms/sorting/merge-sort",
      "algorithms/sorting/quicksort"
    ],
    "commonly_confused_with": [
      "best case != overall quality",
      "in-place != O(1) space (quicksort uses O(log n) stack)",
      "stable != correct"
    ]
  },
  "sources": [
    {
      "num": 1,
      "citation": "CLRS 4th ed. \u00a78.1 (lower bound proof)",
      "tier": 1
    },
    {
      "num": 2,
      "citation": "Peters 2002 Timsort",
      "tier": 1
    },
    {
      "num": 3,
      "citation": "Knuth TAOCP Vol.3 \u00a75",
      "tier": 1
    },
    {
      "num": 4,
      "citation": "Sedgewick & Wayne Algorithms 4th ed. Ch.2",
      "tier": 1
    }
  ]
}