Interactive sorting algorithm visualizer with real-time animations
Description • Features • Installation • Usage • Algorithms
An educational Python project that demonstrates how various sorting algorithms work through real-time interactive animations. The visualizer helps build intuition for algorithmic behavior by showing each comparison, swap, and merge step as it happens.
- Bubble Sort — simple algorithm with clear visualization of comparisons and swaps
- Quick Sort — efficient divide-and-conquer algorithm with partition visualization
- Merge Sort — stable algorithm showing the split-and-merge process
- Interactive animation — step-by-step visualization of every algorithm operation
- Color coding — active elements are highlighted during sorting
- Configurable parameters — adjustable array size and animation speed
- Python 3.7+
- pip
- Clone the repository:
git clone https://github.com/CHUKEPC/sorting_visualizer.git
cd sorting_visualizer- Install dependencies:
pip install -r requirements.txtRun the program and select an algorithm from the menu:
python sorting_visualizer.pyfrom sorting_visualizer import SortingVisualizer
# Create a visualizer with an array of 30 elements
visualizer = SortingVisualizer(size=30)
# Visualize Bubble Sort
visualizer.visualize(algorithm='bubble', speed=100)
# Visualize Quick Sort
visualizer.visualize(algorithm='quick', speed=100)
# Visualize Merge Sort
visualizer.visualize(algorithm='merge', speed=100)custom_data = [64, 34, 25, 12, 22, 11, 90, 5, 77, 88]
visualizer = SortingVisualizer(data=custom_data)
visualizer.visualize(algorithm='quick')visualizer = SortingVisualizer(size=20)
# Fast animation (10 ms between frames)
visualizer.visualize(algorithm='bubble', speed=10)
# Slow animation (500 ms between frames)
visualizer.visualize(algorithm='bubble', speed=500)- Red bars — elements being compared or moved in the current step
- Blue bars — remaining array elements
- Green bars — final sorted state
- Step counter — displays the current step number and total steps
- Python 3.7+
- Matplotlib — chart rendering and animation
- NumPy — array operations (optional)
sorting_visualizer/
├── sorting_visualizer.py # Main module with classes and algorithms
├── requirements.txt # Project dependencies
├── README.md # Documentation (English)
├── README_RU.md # Documentation (Russian)
├── .gitignore # Git ignore rules
└── LICENSE # MIT License
| Parameter | Type | Description | Default |
|---|---|---|---|
data |
List[int] |
Initial data array | None |
size |
int |
Array size (if data is not provided) |
30 |
| Parameter | Type | Description | Default |
|---|---|---|---|
algorithm |
str |
Algorithm: 'bubble', 'quick', 'merge' |
'bubble' |
speed |
int |
Animation speed (ms between frames) | 50 |
- Time complexity: O(n²)
- Stable: Yes
- Notes: Simple to understand but slow for large arrays
- Time complexity: O(n log n) average, O(n²) worst case
- Stable: No
- Notes: One of the most efficient general-purpose sorting algorithms
- Time complexity: O(n log n)
- Stable: Yes
- Notes: Guaranteed O(n log n) performance, requires additional memory
Contributions are welcome! To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.
CHUKEPC
- GitHub: @CHUKEPC
- Telegram: @ArtyomRoyal