A desktop application that visualizes popular sorting algorithms through animated bar graphs.
The project is designed to make Data Structures & Algorithms (DSA) easier to understand by allowing users to watch sorting oprations step by step.
Sorting Visualizer is a graphical desktop application developed using Python and Tkinter.
Instead of simply displaying the final sorted result, the application represents array elements as vertical bars and updates the graph while the sorting algorithm is running.
The project combines Python programming, GUI development, Data Structures, Algorithms, recursion, and algorithm visualization in one application.
✅ Interactive graphical user interface built with Tkinter
✅ Generate random arrays
✅ Enter custom array manually
✅ Five implemented sorting algorithms
✅ Adjustable visualization speed
✅ Real-time bar graph visualization
✅ Color-based sorting visualization
✅ Reset visualization anytime
✅ Detect already sorted arrays
✅ Displays the sorted result after completion
✅ Close the application directly from the GUI
| Algorithm | Time Complexity | Space Complexity |
|---|---|---|
| Bubble Sort | O(n²) | O(1) |
| Selection Sort | O(n²) | O(1) |
| Insertion Sort | O(n²) | O(1) |
| Merge Sort | O(n log n) | O(n) |
| Quick Sort | O(n log n) Average | O(log n) |
Bubble Sort repeatedly compares adjacent elements and swaps them when they are in the wrong order.
Selection Sort searches for the smallest element in the unsorted portion of the array and places it in its correct position.
Insertion Sort builds the sorted portion of the array one element at a time.
It works similarly to arranging playing cards in your hand.
Merge Sort is a Divide and Conquer algorithm.
It recursively divides the array into smaller parts and then merges the sorted parts together.
Quick Sort is another Divide and Conquer algorithm.
The implementation selects a pivot and partitions the array around it.
Click Create Array to generate a random array.
The current implementation generates:
Array Size: 20
Minimum Value: 0
Maximum Value: 100
Example:
[42, 17, 89, 31, 76, 5, 63, 28, ...]
Users can manually enter numbers separated by commas.
Example:
12,5,8,20,3,9,15
After entering the values, click:
Enter Input
The array will then be displayed on the visualization canvas.
Choose one of the available algorithms:
- Merge Sort
- Quick Sort
- Bubble Sort
- Selection Sort
- Insertion Sort
Three visualization speeds are available:
| Speed | Description |
|---|---|
| ⚡ Fast | Quickly displays the sorting process |
| 🚶 Medium | Balanced visualization speed |
| 🐢 Slow | Slower animation for learning |
For understanding the algorithm step by step, Slow mode is recommended.
After selecting an algorithm and preparing the array, click:
Sort
The application starts the selected sorting algorithm and updates the visualization during execution.
Click:
Reset Graph
to clear the current array and visualization canvas.
Click:
Close
to exit the application.
The array represented using vertical bars.
The height of each bar corresponds to its value.
Different colors represent different stages during sorting.
| Color | Meaning |
|---|---|
| 🔵 Blue | Default array elements |
| 🟡 Yellow | Active element / comparison |
| 🔴 Red | Another active element / sorting operation |
Colors can vary slightly between algorithms because each algorithm has its own visualization logic.
Python 3
Tkinter
ttk
random
time
tkinter.messagebox
No external Python packages are required for the current version.
Sorting-Visualizer/
│
├── sorting_visualizer.py
|
└── README.md
Before running the project, make sure you have:
-
Python 3.x
-
Tkinter
Tkinter is included with most standard Python installations.
You can test Tkinter with:
python -m tkinter
This project helps understand:
- Sorting algorithms
- Algorithm visualization
- Recursion
- Divide and Conquer
- GUI Programming
- Event-driven Programming
- Python Tkinter
Planned improvements include:
⬜ Heap Sort
⬜ Radix Sort
⬜ Counting Sort
⬜ Shell Sort
⬜ Array size slider
⬜ Pause / Resume
⬜ Step-by-step execution
⬜ Dark Mode
⬜ Improved UI/UX
⬜ Complexity comparison charts
⬜ Execution-time measurement
⬜ Number of comparisons
⬜ Number of swaps
⬜ Statistics dashboard
⬜ Sound effects
⬜ Algorithm explanation panel
⬜ Better animation system
If you found this project helpful, consider giving it a ⭐ on GitHub.
It helps others discover the project and motivates future development.