A beautiful desktop application built with PyQt for visualizing sorting algorithms step-by-step with interactive controls.
-
🎯 5 Sorting Algorithms:
- Bubble Sort
- Quick Sort
- Merge Sort
- Insertion Sort
- Selection Sort
-
🎮 Interactive Desktop Controls:
▶️ Play/Pause - Watch the animation or pause it- ➡️ Step Forward - Move to next step
- ⬅️ Step Back - Move to previous step
- ⏮️ Reset - Start over
- ⏭️ Go to End - Jump to final result
- 🎚️ Speed Control - Adjust animation speed with slider
- 📏 Array Size - Change the number of elements to sort
- 🎲 Generate New Array - Create random arrays to sort
-
📊 Rich Visual Feedback:
- Blue bars: Unsorted elements
- Orange bars: Elements being compared
- Red bars: Elements being swapped/moved
- Green bars: Elements in their final sorted position
- Real-time statistics: Comparisons, Swaps, Current Step
- Algorithm complexity information
- Progress tracking
-
🎨 Modern PyQt Interface:
- Native desktop application
- Responsive bar chart visualization
- Control panel with buttons and sliders
- Color-coded legend
- Algorithm selection dropdown
- Real-time performance metrics
- Python 3.7 or higher
- PyQt6 or PySide6
- numpy
-
Clone or download this project
-
Install dependencies:
pip install -r requirements.txt
Run the PyQt desktop application:
python3 pyqt_visual.py- Select an algorithm from the dropdown menu at the top
- Adjust array size using the "Array Size" slider
- Click "Generate New Array" to create a new random array
- Control the visualization:
- Click "Play" to start the animation (button changes to "Pause")
- Click "Pause" to stop the animation
- Click "Step Forward" to advance one step at a time
- Click "Step Back" to review previous steps
- Click "Reset" to start over
- Click "Go to End" to see the final sorted array
- Adjust speed using the "Speed" slider
- View statistics - Comparisons, swaps, and current step are displayed in real-time
sorting-visualizer/
├── pyqt_visual.py # PyQt desktop application (MAIN)
├── requirements.txt # Python dependencies
├── README.md # This file
├── algorithms/ # Sorting algorithm implementations
│ ├── __init__.py
│ ├── bubble_sort.py
│ ├── quick_sort.py
│ ├── merge_sort.py
│ ├── insertion_sort.py
│ └── selection_sort.py
└── tests/ # Unit tests for algorithms
├── test_bubble_sort.py
├── test_insertion_sort.py
├── test_merge_sort.py
├── test_quick_sort.py
└── test_selection_sort.py
| Algorithm | Time (Best) | Time (Average) | Time (Worst) | Space |
|---|---|---|---|---|
| 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) |
- Change color scheme: Edit the color constants in
pyqt_visual.py - Add new algorithms: Create a new file in
algorithms/following the generator pattern - Modify UI layout: Update the PyQt widget layout in
pyqt_visual.py - Adjust visualization: Modify the bar chart drawing logic
Run unit tests to verify algorithm correctness:
python3 -m pytest tests/Or run tests individually:
python3 -m pytest tests/test_quick_sort.py -vVideo link: https://drive.google.com/file/d/10-eOmClBH2gLHRrKiFRDyx_jP0pQijCA/view?usp=drive_link