Sorting Algorithms Comparison

Time and space complexity comparison of sorting algorithms: Bubble, Selection, Insertion, Merge, Quick, Heap, Counting, and Radix Sort with stability notes.

  • JSON5,630 B
  • YAML3,364 B · −40%
  • TOON2,197 B · −61%

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 it 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.

Watch out for

  • 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.

The data

Algorithms

NameBestAverageWorstSpaceStable
Bubble SortO(n)O(n^2)O(n^2)O(1)true
Selection SortO(n^2)O(n^2)O(n^2)O(1)false
Insertion SortO(n)O(n^2)O(n^2)O(1)true
Merge SortO(n log n)O(n log n)O(n log n)O(n)true
Quick SortO(n log n)O(n log n)O(n^2)O(log n)false
Heap SortO(n log n)O(n log n)O(n log n)O(1)false
Counting SortO(n+k)O(n+k)O(n+k)O(k)true
Radix SortO(d(n+k))O(d(n+k))O(d(n+k))O(n+k)true
TimsortO(n)O(n log n)O(n log n)O(n)true
IntrosortO(n log n)O(n log n)O(n log n)O(log n)false
Bucket SortO(n + k)O(n + k)O(n^2)O(n + k)true
Shell SortO(n log n)Depends on gap sequenceO(n^2) for simple gapsO(1)false

Fields

The shape of this dataset, read from the data itself: every column, its type and a real value. Agents can use this to plan a query without fetching the whole document.

SectionFieldTypeExample
algorithmsnamestringBubble Sort
algorithmsbeststringO(n)
algorithmsaveragestringO(n^2)
algorithmsworststringO(n^2)
algorithmsspacestringO(1)
algorithmsstablebooleantrue

Fetch the same bytes

The static files contain the same reference rows as the API, with no API rate limit. Live metadata, such as view counts, may differ. Use the API for content negotiation; use the static files for a cacheable snapshot.

curl "https://yjtoon.com/api/dataset/sorting-algorithms-comparison?format=toon"
const res = await fetch(
  "https://yjtoon.com/static-data/dataset/sorting-algorithms-comparison.toon"
);
const toon = await res.text();

Rate limit: 120 requests per minute per IP, no key and no signup. API reference →

Topics

  • algorithms
  • sorting
  • complexity
  • big-o

Search the library

Search by a topic, title, or keyword.

Start with a collection

Browse all 205 datasets