A modern, interactive visualization tool for understanding sorting algorithms through beautiful animations and real-time statistics.
- Bubble Sort - Simple comparison-based algorithm
- Insertion Sort - Efficient for small datasets
- Selection Sort - In-place comparison sorting
- Merge Sort - Divide and conquer approach
- Quick Sort - Efficient divide and conquer
- Heap Sort - Binary heap-based sorting
- Multiple Themes: Dark, Light, and Neon themes
- Real-time Statistics: Comparisons, swaps, array accesses, and timing
- Color-coded Elements: Different colors for comparing, swapping, and sorted elements
- Smooth Animations: Fluid transitions and visual feedback
- Responsive Design: Adaptive layout for different screen sizes
- Speed Control: Adjustable animation speed (1-10)
- Step Mode: Step through algorithms one operation at a time
- Direction Control: Ascending or descending sort
- Array Size: Dynamic array sizing (10-200 elements)
- Data Distributions: Random, sorted, reverse, and nearly sorted arrays
- Frame Recording: Capture every frame of the sorting process
- GIF Creation: Automatically generate animated GIFs
- Video Export: Convert frames to MP4 videos with ffmpeg
- Batch Processing: Record all algorithms automatically
- High Quality: Professional-grade output for presentations
- Python 3.7 or higher
- pip package manager
-
Clone the repository:
https://github.com/MUHAMMEDHAFEEZ/Algorithm-Visualizer.git cd Algorithm-Visualizer
-
Install dependencies:
pip install -r requirements.txt
-
Run the application:
python main.py
# Record all algorithms with frame capture
python demo.py --record
# Record and create GIFs automatically
python demo.py --record --gif
# Ultra-fast demo mode (smaller arrays, faster execution)
python demo.py --express
# Express mode with recording
python demo.py --express --record
# Use the interactive recording script
./record.sh # macOS/Linux
record.bat # Windows
# Install ffmpeg first
brew install ffmpeg # macOS
# sudo apt install ffmpeg # Linux
# Create MP4 from recorded frames
ffmpeg -framerate 30 -i recordings/bubble_sort/frame_%06d.png \
-c:v libx264 -pix_fmt yuv420p bubble_sort.mp4
- Automatic Frame Capture: Every animation frame saved as PNG
- GIF Generation: Animated GIFs with optimized size
- Video Export: High-quality MP4 videos via ffmpeg
- Batch Processing: Record all algorithms in sequence
- Professional Quality: Perfect for presentations and education
- Speed Modes: Express mode for quick demos, normal mode for detailed viewing
See RECORDING_GUIDE.md for detailed instructions.
Key | Action |
---|---|
SPACE |
Start/Pause sorting |
R |
Reset array with new random values |
A |
Set to ascending order |
D |
Set to descending order |
T |
Cycle through themes |
S |
Toggle step mode |
ESC |
Exit application |
Key | Algorithm |
---|---|
1 |
Bubble Sort |
2 |
Insertion Sort |
3 |
Selection Sort |
4 |
Merge Sort |
5 |
Quick Sort |
6 |
Heap Sort |
Key | Action |
---|---|
โ |
Increase speed |
โ |
Decrease speed |
+ |
Increase array size |
- |
Decrease array size |
Key | Distribution |
---|---|
F1 |
Random array |
F2 |
Sorted array |
F3 |
Reverse sorted array |
F4 |
Nearly sorted array |
The application follows a clean, modular architecture:
DrawInformation
: Handles rendering and visual state managementSortingStats
: Tracks algorithm performance metricsColorScheme
: Manages theme-based color palettes- Algorithm Functions: Generator-based implementations for smooth visualization
- Generator-based sorting: Allows for smooth step-by-step visualization
- Efficient rendering: Only updates necessary screen regions
- Adaptive frame rates: Adjusts based on sorting speed settings
- ๐ต Blue/Primary: Default elements
- ๐ก Yellow/Comparing: Elements being compared
- ๐ด Red/Swapping: Elements being swapped
- ๐ข Green/Sorted: Elements in final position
- ๐ฃ Purple/Current: Current element being processed
Algorithm | Time Complexity (Best/Average/Worst) | Space Complexity |
---|---|---|
Bubble Sort | O(n) / O(nยฒ) / O(nยฒ) | O(1) |
Insertion Sort | O(n) / O(nยฒ) / O(nยฒ) | O(1) |
Selection Sort | O(nยฒ) / O(nยฒ) / O(nยฒ) | O(1) |
Merge Sort | O(n log n) / O(n log n) / O(n log n) | O(n) |
Quick Sort | O(n log n) / O(n log n) / O(nยฒ) | O(log n) |
Heap Sort | O(n log n) / O(n log n) / O(n log n) | O(1) |
- Modern dark interface with high contrast
- Ideal for extended viewing sessions
- Professional appearance
- Clean, minimalist design
- Easy on the eyes in bright environments
- Classic and accessible
- Vibrant, eye-catching colors
- Cyberpunk-inspired aesthetic
- Great for demonstrations
To add a new sorting algorithm:
-
Create a generator function following the pattern:
def your_sort(draw_info: DrawInformation, ascending: bool = True) -> Generator[bool, None, None]: # Your sorting logic here # Use yield True to pause for visualization # Update draw_info.stats for metrics
-
Add it to the algorithms dictionary in
main()
-
Assign a key binding for selection
Edit the ColorScheme.get_theme()
method to customize colors or add new themes.
This visualizer is perfect for:
- Computer Science Education: Understanding algorithm behavior
- Interview Preparation: Visualizing common sorting algorithms
- Research: Comparing algorithm performance
- Presentations: Demonstrating sorting concepts
Contributions are welcome! Here's how you can help:
- 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
- Additional sorting algorithms (Radix, Counting, etc.)
- Sound effects and audio feedback
- Export functionality (GIF, video)
- Performance benchmarking tools
- Mobile/web version
This project is licensed under the MIT License - see the LICENSE file for details.
- Pygame Community for the excellent graphics library
- Algorithm Visualizer projects for inspiration
- Computer Science educators for algorithm explanations
If you encounter any issues or have questions:
- Open an issue on GitHub
- Check the documentation
Made with โค๏ธ for computer science education and algorithm visualization BY HAFEEZ