Sorting Algorithms
Comparison of fundamental sorting algorithms with time and space complexity.
Comparison of fundamental sorting algorithms with time and space complexity.
Sorting algorithms with best, average and worst time, space, stability and notes: bubble, selection, insertion, merge, quick, heap, counting and radix sort, extended with Timsort, introsort, bucket sort and shell sort.
| Name | Best | Average | Worst | Space | Stable | Notes |
|---|---|---|---|---|---|---|
| Bubble Sort | O(n) | O(n^2) | O(n^2) | O(1) | true | Simple but inefficient for large inputs. |
| Selection Sort | O(n^2) | O(n^2) | O(n^2) | O(1) | false | Minimizes swaps; good when write cost is high. |
| Insertion Sort | O(n) | O(n^2) | O(n^2) | O(1) | true | Efficient for small or nearly sorted datasets. |
| Merge Sort | O(n log n) | O(n log n) | O(n log n) | O(n) | true | Consistent performance; good for linked lists. |
| Quick Sort | O(n log n) | O(n log n) | O(n^2) | O(log n) | false | In-place; widely used in practice. |
| Heap Sort | O(n log n) | O(n log n) | O(n log n) | O(1) | false | Guaranteed O(n log n); in-place. |
| Counting Sort | O(n + k) | O(n + k) | O(n + k) | O(k) | true | Only for integers in bounded range. |
| Radix Sort | O(nk) | O(nk) | O(nk) | O(n + k) | true | Sorts by digit position; k = number of digits. |
| Timsort | O(n) | O(n log n) | O(n log n) | O(n) | true | Hybrid of merge and insertion sort that exploits existing runs; used in Python and Java for objects. |
| Introsort | O(n log n) | O(n log n) | O(n log n) | O(log n) | false | Starts as quicksort and falls back to heapsort when recursion gets too deep; common in C++ std::sort. |
| Bucket Sort | O(n + k) | O(n + k) | O(n^2) | O(n + k) | true | Distributes items into buckets and sorts each; good for uniformly distributed input. |
| Shell Sort | O(n log n) | Depends on gap sequence | O(n^2) for simple gaps | O(1) | false | Generalizes insertion sort with diminishing gaps; simple and in place. |
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.
| Section | Field | Type | Example |
|---|---|---|---|
| data | name | string | Bubble Sort |
| data | best | string | O(n) |
| data | average | string | O(n^2) |
| data | worst | string | O(n^2) |
| data | space | string | O(1) |
| data | stable | boolean | true |
| data | notes | string | Simple but inefficient for large inputs. |
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?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 →