A desktop application built in Python that visualizes various sorting algorithms in real-time. This tool helps students and developers understand the mechanics, step-by-step operations, and time complexities of basic, intermediate, and advanced sorting algorithms through dynamic graphical animations.
Project/
│
├── .venv/ # Python Local Virtual Environment
├── build/ # PyInstaller temporary build artifacts
├── dist/ # Standalone executable distribution folder
│ └── main.exe # Production-ready executable app for clients
│
├── main.py # Application entry point & runtime loop
├── gui.py # Refactored OOP UI Framework & Canvas Rendering
├── algorithms.py # Visual Sorting Engines (Bubble, Selection, etc.)
├── requirements.txt # External project dependencies (Matplotlib)
│
├── utils/
│ └── benchmarking.py # Independent Performance Analysis Engine
│
└── assets/
└── performance_charts/ # Generated high-res benchmarking comparison plots
The application visualizes 5 core sorting algorithms, divided by their algorithmic complexity and paradigm:
- Bubble Sort: A simple comparison-based algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.
- Selection Sort: Divides the array into sorted and unsorted parts, repeatedly finds the minimum element from the unsorted part, and puts it at the beginning.
-
Insertion Sort (
$O(n^2)$ ): Builds the final sorted array one item at a time by inserting elements into their proper position relative to the already-sorted elements. -
Merge Sort (
$O(n \log n)$ ): A classic Divide and Conquer algorithm. It divides the input array into two halves, calls itself for the two halves, and then merges the two sorted halves.
-
Quick Sort (
$O(n \log n)$ ): Another Divide and Conquer powerhouse. It picks an element as a pivot and partitions the given array around the picked pivot so that smaller elements go left and larger ones go right.
| Algorithm | Best Case | Average Case | Worst Case | Space Complexity | Paradigm |
|---|---|---|---|---|---|
| Bubble Sort | Brute Force | ||||
| Selection Sort | Brute Force | ||||
| Insertion Sort | Incremental | ||||
| Merge Sort | Divide & Conquer | ||||
| Quick Sort | Divide & Conquer |
- Role: Building the main application interface and handling graphical rendering.
- Tasks:
- Design the desktop window layout using Tkinter or PyQt.
- Create interactive controls: Start/Pause buttons, speed control sliders, and array size selectors.
- Implement the rendering logic to display numbers as dynamic vertical bars.
- Handle real-time color updates (e.g., highlighting comparisons, swaps, and pivots).
- Role: Implementing foundational sorting mechanisms.
- Tasks:
- Manually code the Bubble Sort and Selection Sort algorithms inside
algorithms.py. - Embed execution delays and trigger state-updates (
draw_callback) after every key comparison or element swap.
- Manually code the Bubble Sort and Selection Sort algorithms inside
- Role: Implementing intermediate-level sorting operations.
- Tasks:
- Manually code the Insertion Sort and Merge Sort algorithms inside
algorithms.py. - Manage data streaming configurations to ensure the step-by-step animation supports array division and merging stages.
- Manually code the Insertion Sort and Merge Sort algorithms inside
- Role: Developing advanced recursive logic and managing full-system integration.
- Tasks:
- Manually code the Quick Sort algorithm with optimized pivot selection methods.
- Implement dynamic Recursion Visualization (handling index active ranges and dimming inactive sub-arrays during partitioning).
- Design the integration framework inside
main.pyto seamlessly connect the backend algorithm engines with the frontend GUI callbacks.
- Role: Quality assurance, empirical benchmarking, and reporting.
-
Tasks:
- Profile and benchmark the runtime performance of all implemented algorithms under different scenarios (Best, Average, Worst cases).
- Generate statistical comparison tables and plot analytical runtime charts using Matplotlib.
- Document time complexities (
$O(n^2)$ vs $O(n \log n)$) and write the final technical report.
You can execute this project either as a standalone desktop application or by running the source code through a Python virtual environment.
No Python installation is required for this option.
- Navigate to the
dist/folder inside the project directory. - Double-click on
main.exeto launch the graphical visualizer instantly.
1. Clone the Repository:
git clone [https://github.com/nour-ayman/sorting-algorithm-visualizer.git](https://github.com/nour-ayman/sorting-algorithm-visualizer.git)
cd Project2. Set Up and Activate the Virtual Environment:
- On Windows (Command Prompt / PowerShell):
python -m venv .venv
.venv\Scripts\activate- On macOS / Linux:
python3 -m venv .venv
source .venv/bin/activate3. Install Dependencies: Ensure your active environment environment has all required libraries by installing the requirements file:
pip install -r requirements.txt4. Execute the Application Framework: Run the core desktop entry-point file:
python main.py5. Run the Empirical Benchmarking Engine:
To profile the sorting performance and generate runtime analysis comparison charts inside assets/performance_charts/:
python utils/benchmarking.pyTo help trace algorithmic internal state changes, the layout implements the following strict visual language:
- 🟦 Blue: Unsorted base array state / Elements outside the active partition scope.
- 🟨 Yellow: Active comparative element tracking (Elements being scanned/evaluated).
- 🟥 Red: Current localized target context (e.g., Quick-Sort Pivot element or Selection-Sort current minimum index).
- 🟪 Purple: Active operating boundary or sub-array partitioning context (Crucial for Merge Sort division visualization).
- 🟩 Green: Successfully swapped element state or Fully Sorted Array blocks.
- Python 3.13 - Core runtime environment.
- Tkinter & TTK - Lightweight built-in native Desktop GUI rendering engine.
- Matplotlib - Data visualization engine for plotting empirical runtime analysis graphs.
- PyInstaller - Standalone pipeline compilation for automated assembly of production-ready
.exereleases.