api: YAML JSON TOON Database
version: 1.0.0
format: json
dataset:
  id: 13
  slug: sorting-algorithms-comparison
  title: Sorting Algorithms Comparison
  description: "Time and space complexity comparison of sorting algorithms: Bubble, Selection, Insertion, Merge, Quick, Heap, Counting, and Radix Sort with stability notes."
  summary: "A comparison of sorting algorithms by best, average and worst time, space and stability: bubble, selection, insertion, merge, quick, heap, counting and radix sort, extended with Timsort, introsort, bucket sort and shell sort."
  use_when:
    - You need to choose a sorting algorithm for data of a given size and shape.
    - You need to know whether a sort is stable.
  caveats:
    - Counting, radix and bucket sort are not comparison sorts and depend on the range or distribution of keys.
    - Library sorts are usually hybrids (Timsort, introsort), so real behavior differs from textbook algorithms.
  related:
    - sorting-algorithms
    - complexity-analysis
    - search-algorithms
    - python-builtins
  category: Data Structures
  category_slug: data-structures
  tags: algorithms,sorting,complexity,big-o
  view_count: 0
  created_at: 1777673262
  updated_at: 1777673262
  entry_count: 12
  fields:
    - section: algorithms
      field: name
      type: string
      example: Bubble Sort
    - section: algorithms
      field: best
      type: string
      example: O(n)
    - section: algorithms
      field: average
      type: string
      example: O(n^2)
    - section: algorithms
      field: worst
      type: string
      example: O(n^2)
    - section: algorithms
      field: space
      type: string
      example: O(1)
    - section: algorithms
      field: stable
      type: boolean
      example: "true"
data:
  algorithms:
    - name: Bubble Sort
      best: O(n)
      average: O(n^2)
      worst: O(n^2)
      space: O(1)
      stable: true
    - name: Selection Sort
      best: O(n^2)
      average: O(n^2)
      worst: O(n^2)
      space: O(1)
      stable: false
    - name: Insertion Sort
      best: O(n)
      average: O(n^2)
      worst: O(n^2)
      space: O(1)
      stable: true
    - name: Merge Sort
      best: O(n log n)
      average: O(n log n)
      worst: O(n log n)
      space: O(n)
      stable: true
    - name: Quick Sort
      best: O(n log n)
      average: O(n log n)
      worst: O(n^2)
      space: O(log n)
      stable: false
    - name: Heap Sort
      best: O(n log n)
      average: O(n log n)
      worst: O(n log n)
      space: O(1)
      stable: false
    - name: Counting Sort
      best: O(n+k)
      average: O(n+k)
      worst: O(n+k)
      space: O(k)
      stable: true
    - name: Radix Sort
      best: O(d(n+k))
      average: O(d(n+k))
      worst: O(d(n+k))
      space: O(n+k)
      stable: true
    - name: Timsort
      best: O(n)
      average: O(n log n)
      worst: O(n log n)
      space: O(n)
      stable: true
    - name: Introsort
      best: O(n log n)
      average: O(n log n)
      worst: O(n log n)
      space: O(log n)
      stable: false
    - name: Bucket Sort
      best: O(n + k)
      average: O(n + k)
      worst: O(n^2)
      space: O(n + k)
      stable: true
    - name: Shell Sort
      best: O(n log n)
      average: Depends on gap sequence
      worst: O(n^2) for simple gaps
      space: O(1)
      stable: false
