Sorting Algorithms

Comparison of fundamental sorting algorithms with time and space complexity.

  • Algorithms
  • 56 entries
  • 8 sections
  • CC0 — public domain

The data

0

Name
Bubble Sort
Best
O(n)
Average
O(n^2)
Worst
O(n^2)
Space
O(1)
Stable
true
Notes
Simple but inefficient for large inputs.

1

Name
Selection Sort
Best
O(n^2)
Average
O(n^2)
Worst
O(n^2)
Space
O(1)
Stable
false
Notes
Minimizes swaps; good when write cost is high.

2

Name
Insertion Sort
Best
O(n)
Average
O(n^2)
Worst
O(n^2)
Space
O(1)
Stable
true
Notes
Efficient for small or nearly sorted datasets.

3

Name
Merge Sort
Best
O(n log n)
Average
O(n log n)
Worst
O(n log n)
Space
O(n)
Stable
true
Notes
Consistent performance; good for linked lists.

4

Name
Quick Sort
Best
O(n log n)
Average
O(n log n)
Worst
O(n^2)
Space
O(log n)
Stable
false
Notes
In-place; widely used in practice.

5

Name
Heap Sort
Best
O(n log n)
Average
O(n log n)
Worst
O(n log n)
Space
O(1)
Stable
false
Notes
Guaranteed O(n log n); in-place.

6

Name
Counting Sort
Best
O(n + k)
Average
O(n + k)
Worst
O(n + k)
Space
O(k)
Stable
true
Notes
Only for integers in bounded range.

7

Name
Radix Sort
Best
O(nk)
Average
O(nk)
Worst
O(nk)
Space
O(n + k)
Stable
true
Notes
Sorts by digit position; k = number of digits.

Fetch the same bytes

The static files are identical to what the API returns, but with no rate limit and no server round trip. Use the API when you want a query and a content type; use the files when you want to cache one document.

curl "https://yjtoon.com/api/dataset/sorting-algorithms?format=toon"
const res = await fetch(
  "https://yjtoon.com/static-data/dataset/sorting-algorithms.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