This is an interactive visualization tool for common sorting algorithms. It intuitively visualizes how sorting algorithms work by displaying the basic operations of a chosen algorithm as it runs on a randomized array.
The following sorting algorithms have been implemented.
Sorting Algorithm | Worst-Case Time Complexity | Average-Case Time Complexity | Best-Case Time Complexity |
---|---|---|---|
Bubble Sort | O(n2) | O(n2) | O(n) |
Selection Sort | O(n2) | O(n2) | O(n2) |
Insertion Sort | O(n2) | O(n2) | O(n) |
Merge Sort | O(n log n) | O(n log n) | O(n log n) |
Quick Sort | O(n2) | O(n log n) | O(n log n) |
Heap Sort | O(n log n) | O(n log n) | O(n log n) |
As an interesting aside, this visualizer provides decent approximations on how the sorting algorithms would perform relative to each other, so the visualizations of each sorting algorithm should roughly reflect the running time complexities above too.
- Clone this repository to your local machine using
https://github.com/jseok1/Sorting-Algorithm-Visualizer.git
. - Use the package manager
pip
to installpygame
.
$ pip install pygame
To launch the visualizer, simply run main.py
.
The following keys map to the following algorithms.
1
- Bubble Sort2
- Selection Sort3
- Insertion Sort4
- Merge Sort5
- Quick Sort6
- Heap Sort
Additionally, you can press r
to randomize the array.