A full-stack Python and Web application designed to visualize, benchmark, and compare 13 sorting algorithms in real time.
- Backend: Python 3.x, Flask (REST API)
- Visualization: Pygame (Generator-driven animations)
- Frontend: HTML5, CSS3, JavaScript ES6 (Fetch API, Async DOM rendering)
- Benchmarking: High-precision timing via
time.perf_counter
- Interactive Web Interface: Custom controls for dataset size, negative numbers flag, and data distribution types (Already sorted, Reverse sorted, Totally random, Nearly sorted).
- Generator-Driven Animation: Pygame visualizer uses Python
yieldgenerators to render array state transitions, element swaps, and a completion sweep without blocking execution. - Dynamic Web Benchmark: Executes all algorithms against identical data configurations and returns a JSON response to construct a dynamic HTML benchmark table.
- I Can't Believe It Can Sort: An unusually simple quadratic exchange sort using two full nested loops.
- Bubble Sort: Repeatedly steps through the list, compares adjacent elements, and swaps out-of-order pairs.
- Selection Sort: In-place comparison algorithm that repeatedly finds the minimum element and places it at the sorted partition.
- Insertion Sort: Builds the sorted array one item at a time by inserting unsorted elements into their correct position.
- Shell Sort: An optimization of insertion sort using decreasing gap sequences to move distant elements efficiently.
- Merge Sort: Recursively splits the array in half, sorts each half, and merges them together.
- Quick Sort: Uses a pivot element to partition the array recursively into smaller and larger sub-arrays.
- Heap Sort: Converts the list into a Max-Heap binary tree to repeatedly extract the largest element.
- Python Sort: Native C-level
list.sort()(Timsort) serving as the baseline benchmark. - Tim Sort: Hybrid sorting algorithm combining Merge Sort and Insertion Sort designed for real-world data patterns.
- Counting Sort: Non-comparison algorithm counting element frequencies to determine exact positions in linear time.
- Radix Sort: Non-comparison algorithm processing numbers digit-by-digit using counting sort as a stable subroutine.
- Bucket Sort: Distributes elements into uniform buckets, sorts each individually, and concatenates the result.
Sort-algorithms/
├── algorithms/ # Pure algorithm implementations (for benchmarks)
│ ├── bubble_sort.py
│ ├── quick_sort.py
│ └── ...
├── algorithms_generator/ # Generator-based algorithm implementations (yielding steps for Pygame visualization)
│ ├── bubble_sort_generator.py
│ ├── quick_sort_generator.py
│ └── ...
├── ui/ # Web frontend interface & Pygame graphics renderer
│ ├── index.html # Dashboard controls & benchmark output section
│ ├── style.css # Layout styling and UI components
│ ├── script.js # Async Fetch API triggers and DOM manipulators
│ └── renderer.py # Pygame canvas rendering logic (bars, swap highlights, green completion state)
├── utils/ # Helper tools
│ └── data_generator.py # Flexible data generation (Already sorted, Reverse sorted, Random, Nearly sorted)
├── main.py # Flask web server & Pygame application orchestrator
└── benchmark.py # Performance measurement engine across all 13 algorithms
-
Install dependencies:
pip install flask pygame
-
Run the application:
python main.py
-
Open in browser: Navigate to
http://localhost:5000/
- Support custom input distributions (already sorted, reverse sorted, totally random, nearly sorted).
- Add execution visualization and benchmark time visualization.
- Add interactive range sliders for animation speed controls.
- Implement UI loading indicators ("Waiting for response...") during benchmark execution.