Watch classic sorting algorithms sort the same 100-element array — step by step.
Each bar is a value. Every frame is one swap or shift.
Same dataset, different strategies — see how efficiency really feels.
pip install -r requirements.txt
python BubbleSort.py # pick any algorithm file belowOn first run, a shared dataset file is generated so every algorithm sorts the exact same input.
| Algorithm | Best | Average | Worst | In-place | Stable |
|---|---|---|---|---|---|
| Bubble Sort | O(n) | O(n²) | O(n²) | Yes | Yes |
| Selection Sort | O(n²) | O(n²) | O(n²) | Yes | No |
| Insertion Sort | O(n) | O(n²) | O(n²) | Yes | Yes |
| Merge Sort | O(n log n) | O(n log n) | O(n log n) | No | Yes |
| Quick Sort | O(n log n) | O(n log n) | O(n²) | Yes | No |
| Heap Sort | O(n log n) | O(n log n) | O(n log n) | Yes | No |
| Counting Sort | O(n + k) | O(n + k) | O(n + k) | No | Yes |
All demos below use the same 100-element array.
RunHeapSort.pyorCountingSort.pylocally for the remaining two.
Repeatedly swaps adjacent out-of-order pairs — simple, but slow.
Builds a sorted prefix one element at a time — great on nearly-sorted data.
Finds the minimum and places it — few writes, many comparisons.
Divide, conquer, merge — consistent O(n log n) performance.
Partition around a pivot — fast in practice, elegant recursion.
| File | Idea |
|---|---|
HeapSort.py |
Max-heap extraction — guaranteed O(n log n), no extra array |
CountingSort.py |
Count occurrences — linear time when values are in a small range |
python HeapSort.py
python CountingSort.pyEvery sorter is a Python generator that yields the array after each step. Matplotlib's FuncAnimation turns those frames into a live bar chart:
def bubbleSort(array):
for i in range(len(array) - 1):
for j in range(i + 1, len(array)):
if array[i] > array[j]:
array[i], array[j] = array[j], array[i]
yield array # ← one animation frameTo regenerate the shared dataset, delete the dataset file and run any script again.
Part of Cool Programming Challenges — a playground of small projects across languages.




