100 sorting algorithms. From O(1) to O(โ). From production-ready to multiverse-borrowing.
python benchmark.py # full benchmark
python benchmark.py -a BubbleSort,TimSort # specific algorithms
python benchmark.py -f Quick --top 5 # filter + top 5
python benchmark.py --list # list all 100
python visualize.py # interactive menu
python visualize.py QuickSort # single animation
python visualize.py Bubble,Merge,Quick # compare side-by-side
python visualize.py --list # list visualizable algorithmsSorting/
โโโ data.py # test datasets
โโโ benchmark.py # auto-benchmark, zero hardcoding
โโโ visualize.py # matplotlib animations, comma-list compare
โโโ algorithms/
โโโ __init__.py # auto-discovery
โโโ *.py # 100 algorithms, one per file
Adding a new algorithm = one new file. Everything else updates automatically.
| Algorithm | Avg | Worst | Stable | Notes |
|---|---|---|---|---|
| TimSort | O(n log n) | O(n log n) | โ | Powers Python sorted() |
| MergeSort | O(n log n) | O(n log n) | โ | Classic divide & conquer |
| IterativeMergeSort | O(n log n) | O(n log n) | โ | No recursion, stack-safe |
| AdaptiveMergeSort | O(n log k) | O(n log n) | โ | k = number of runs |
| WeaveMergeSort | O(n log n) | O(n log n) | โ | Cache-friendly bottom-up |
| InPlaceMergeSort | O(n logยฒn) | O(n logยฒn) | โ | O(1) extra memory |
| MergeSortParallel | O(n log n) | O(n log n) | โ | Multi-threaded |
| QuickSort | O(n log n) | O(nยฒ) | โ | Fastest in practice |
| RandomizedQuickSort | O(n log n) | O(nยฒ) rare | โ | Random pivot |
| StableQuickSort | O(n log n) | O(nยฒ) | โ | Extra memory for stability |
| TernarySplitQuickSort | O(n log n) | O(n log n) | โ | Dutch flag partition |
| DualPivotQuickSort | O(n log n) | O(n log n) | โ | Java Arrays.sort() |
| KnuthSort | O(n log n) | O(n log n) | โ | 3-way, Knuth vol.3 |
| IntroSort | O(n log n) | O(n log n) | โ | C++ std::sort |
| HeapSort | O(n log n) | O(n log n) | โ | Guaranteed, in-place |
| SmoothSort | O(n log n) | O(n log n) | โ | Leonardo heap |
| ShellSort | O(n logยฒn) | O(n logยฒn) | โ | Surprisingly fast |
| GrailSort | O(n log n) | O(n log n) | โ | O(1) memory |
| WikiSort | O(n log n) | O(n log n) | โ | Block merge, O(1) memory |
| QuadSort | O(n log n) | O(n log n) | โ | Sorting network for 4-blocks |
| BitonicSort | O(n logยฒn) | O(n logยฒn) | โ | GPU-friendly |
| BitonicMergeSort | O(n logยฒn) | O(n logยฒn) | โ | Explicit merge network |
| SortingNetwork | O(n logยฒn) | O(n logยฒn) | โ | Fixed comparator network |
| TreeSort | O(n log n) | O(nยฒ) | โ | BST in-order |
| TournamentSort | O(n log n) | O(n log n) | โ | Tournament tree |
| PatienceSort | O(n log n) | O(n log n) | โ | Patience solitaire |
| PatienceOptSort | O(n log n) | O(n log n) | โ | Binary search piles |
| PatienceSortIterative | O(n log n) | O(n log n) | โ | No recursion |
| PatienceMergeSort | O(n log n) | O(n log n) | โ | Patience + k-way merge |
| DropMergeSort | O(n log n) | O(n log n) | โ | O(n) on nearly sorted |
| StrandSort | O(nยฒ) worst | O(n) best | โ | Extracts sorted runs |
| WeaveSort | O(n log n) | O(n log n) | โ | Bottom-up weaving |
| CartesianSort | O(n log n) | O(nยฒ) | โ | Cartesian tree |
| FunnelSort | O(n logยฒn) | O(n logยฒn) | โ | Cache-oblivious |
| SampleSort | O(n log n) | O(n log n) | โ | Parallel-friendly |
| HybridSort | O(n log n) | O(n log n) | โ | Adaptive: picks best algo |
| BlockSort | O(n log n) | O(n log n) | โ | sqrt(n) blocks |
| LazySort | O(n log n) | O(n log n) | โ | Defers sort until access |
| YogurtSort | O(n log n) | O(n log n) | โ | Natural runs + merge |
| Algorithm | Complexity | Constraint |
|---|---|---|
| CountingSort | O(n + k) | integers, range k |
| RadixSort | O(nk) | integers |
| BucketSort | O(n + k) avg | uniform distribution |
| PigeonHoleSort | O(n + k) | integers, range โ n |
| PigeonSort | O(n + k) | integers, pigeonhole variant |
| PigeonRaceSort | O(n + k) | satirical pigeonhole |
| BeadSort | O(S) | non-negative integers |
| GravitySort | O(S) | non-negative integers |
| SpreadSort | O(n) avg | Boost C++ |
| FlashSort | O(n) avg | uniform distribution |
| PostmanSort | O(nk) | MSD Radix |
| AmericanFlagSort | O(nk) | MSD, in-place |
| ProxmapSort | O(n) avg | uniform distribution |
| Algorithm | Stable | Notes |
|---|---|---|
| BubbleSort | โ | The famous one |
| ReverseBubbleSort | โ | Scans right-to-left |
| AntiBubbleSort | โ | Reverses correctly ordered pairs |
| InsertionSort | โ | Best on nearly-sorted |
| BinaryInsertionSort | โ | Binary search for position |
| RecursiveInsertionSort | โ | Recursive variant |
| SelectionSort | โ | Fewest writes |
| ExchangeSort | โ | Every element vs every other |
| CocktailShakerSort | โ | Bidirectional bubble |
| CombSort | โ | Bubble with gap > 1 |
| GnomeSort | โ | Garden gnome algorithm |
| NaiveSort | โ | Restarts after every swap |
| OddEvenSort | โ | GPU/parallel design |
| EvenOddTranspositionSort | โ | SIMD variant |
| CycleSort | โ | Minimal writes |
| PancakeSort | โ | Prefix reversals only |
| BurntPancakeSort | โ | Two-sided pancakes |
| PancakeNumberSort | โ | Tracks flip sequence |
| PancakeSortOptimized | โ | 2*(n-1) flips max |
| LibrarySort | โ | Insertion with gaps |
| ShuffleSort | โ | Fisher-Yates shuffle attempt |
| EfficientBogoSort | โ | "Optimized" BogoSort |
| UnstableSort | โ | Deliberately unstable |
| XorSort | โ | XOR swap trick |
| ZigZagSort | โ | Zigzag weave |
| Algorithm | Notes |
|---|---|
| GeneticSort | Evolutionary, crossover + mutation |
| AntSort | Ant colony optimization |
| QuantumSort | Simulates quantum parallelism |
| VinoSort | Wine decanting metaphor ๐ท |
| YogurtSort | Fermentation/culture merging |
| JigsawSort | Puzzle-piece block fitting |
| Algorithm | Complexity | Lore |
|---|---|---|
| QuantumBogoSort | O(1)โ | Borrows result from a sorted parallel universe |
| BogoSort | O(n ยท n!) | Random shuffle until sorted |
| BogoBogoSort | O((n+1)!) | n > 4 will outlive the sun |
| StalinSort | O(n) | Removes non-conforming elements |
| SlowSort | O(n^(log n/log log n)) | Deliberately slowest correct sort |
| StoogeSort | O(n^2.7) | "Multiply and surrender" |
| MiracleSort | O(โ) | Awaits cosmic radiation |
| SleepSort | O(max(n)) | Thread sleep = element value |
| GaslitSort | O(1) (claimed) | Denies having sorted anything |
| McCarthySort | O(n! ยท n) | Removes random elements recursively |
| CorruptionSort | O(n log n) + bugs | Sorts then corrupts 8% |
| AntiBubbleSort | O(nยฒ) | Unsorting machine |
| EscapeSort | O(nยฒ) | Elements try to escape position |
| OscarSort | O(nยฒ) | Complains the entire time |
| DrunkSort | O(?) | 70% correct, 30% chaos |
| ChatGPTSort_v1 | O(n log n) + 10% hallucinations | Context window, content policy |
| ChatGPTSort_v2 | O(๐ธ/token) | Real OpenAI API |
| ClaudeSort | O(n log n) + questions | Asks for context first |
โ Time complexity: O(1) โ just an observation. The sorted universe already exists. We just needed to look.
Every letter AโZ has at least one algorithm:
A B C D E F G H I J K L M
โ โ โ โ โ โ โ โ โ โ โ โ โ
N O P Q R S T U V W X Y Z
โ โ โ โ โ โ โ โ โ โ โ โ โ
All 26/26 covered. ๐
from algorithms import merge_sort, quick_sort, tim_sort, REGISTRY
data = [64, 34, 25, 12, 22, 11, 90]
print(merge_sort(data)) # [11, 12, 22, 25, 34, 64, 90]
# iterate all algorithms
for name, func in REGISTRY.items():
result = func(data[:])# Benchmark examples
python benchmark.py # all 100
python benchmark.py -a "Merge,Quick,Tim" # compare three
python benchmark.py -f Pancake --size 50 # filter + custom size
python benchmark.py --list # full list
# Visualizer examples
python visualize.py # menu
python visualize.py QuickSort --size 30 # single, 30 elements
python visualize.py Bubble,Merge,Quick # compare 3 side-by-side
python visualize.py --list # list visualizable- Create
algorithms/XxxSort.py - Implement
xxx_sort(list)โ must return a new list, not modify in-place - Done.
benchmark.py,__init__.pydetect it automatically.
# algorithms/XyzSort.py
from data import *
def xyz_sort(lista):
lst = lista.copy()
# your implementation
return lst
if __name__ == "__main__":
from data import losowa
print(xyz_sort(losowa))# in your own file or directly in visualize.py
from visualize import register_algorithm
def _xyz_steps(lst):
a = lst[:]
# yield (state, compare_indices, sorted_indices, label)
yield a[:], [0, 1], [], "Comparing"
yield a[:], [], list(range(len(a))), "Done!"
register_algorithm("XYZ Sort", _xyz_steps)Simple rules:
- One file = one algorithm (
XxxSort.py) - Return a new list (
lst = lista.copy()at the start) - Top comment: complexity + how it works
- Must pass:
assert xxx_sort([3,1,2]) == [1,2,3] - Satirical algorithms welcome (see
QuantumBogoSort.py,GaslitSort.py)
Ideas:
- ๐งฌ More evolutionary algorithms (Particle Swarm, Simulated Annealing)
- ๐ LocaleSort โ locale-aware string sorting
- ๐ข More radix variants (MSD, ternary)
- ๐ฎ Any algorithm with a good story
Every algorithm you add lives here alongside QuantumBogoSort. That's an honor.
Fastest (theory): QuantumBogoSort โ O(1) in the surviving universe
Fastest (practice): SpreadSort โ O(n) average
Slowest (correct): SlowSort โ O(n^(log n / log log n))
Slowest (overall): MiracleSort โ O(โ)
Most honest: StalinSort โ always O(n), always "sorted"
Most philosophical: QuantumBogoSort โ the sorted list already exists, somewhere
Most paranoid: GaslitSort โ denies everything
Most Java: DualPivotQuick โ literally what Java uses
Most Python: TimSort โ literally what Python uses
Most pigeon: PigeonRaceSort โ n pigeons, simultaneously airborne
"Every sorting algorithm is correct if you define 'sorted' appropriately."
โ StalinSort Documentation, 2024