An interactive algorithm visualization tool built with Python, Streamlit, and Matplotlib.
This project demonstrates how classic sorting algorithms work step by step through real-time bar chart animation. It also displays algorithm metadata such as time complexity, space complexity, stability, and runtime statistics including comparisons and swaps/writes.
- Interactive web interface built with Streamlit
- Visualizes sorting algorithms step by step
- Supports the following algorithms:
- Bubble Sort
- Selection Sort
- Insertion Sort
- Merge Sort
- Quick Sort
- Displays:
- Best / Average / Worst time complexity
- Space complexity
- Stability
- Core algorithm idea
- Comparisons
- Swaps / Writes
algorithm-visualizer/
├── algorithms/
│ ├── init.py
│ ├── bubble_sort.py
│ ├── selection_sort.py
│ ├── insertion_sort.py
│ ├── merge_sort.py
│ └── quick_sort.py
├── app.py
├── requirements.txt
├── README.md
└── .gitignore
- Python
- Streamlit
- Matplotlib
Each sorting algorithm is implemented as a generator so that the current array state can be yielded step by step during execution.
This allows the visualization layer to:
- update the bar chart in real time
- highlight active indices
- track comparisons and swaps/writes dynamically
Repeatedly compares adjacent elements and swaps them if they are in the wrong order.
Repeatedly selects the minimum element from the unsorted portion and places it at the front.
Builds the sorted array one element at a time by inserting each element into its correct position.
Uses divide-and-conquer to recursively split the array and merge sorted halves.
Uses a pivot-based partition strategy and recursively sorts subarrays.
Clone the repository:
git clone https://github.com/YOUR_USERNAME/algorithm-visualizer.git
cd algorithm-visualizer
Create environment:
conda create -n algo-vis python=3.10 -y
conda activate algo-vis
Install dependencies:
pip install -r requirements.txt
Run the application:
streamlit run app.py
or
python -m streamlit run app.py
Through this project, I learned how to:
- implement sorting algorithms in generator form for incremental visualization
- build interactive algorithm demos with Streamlit
- connect algorithm behavior with complexity analysis
- present algorithmic concepts through a lightweight engineering product
- Used generator-based algorithm implementations to expose intermediate states during execution
- Used Matplotlib bar charts for simple and interpretable visualization
- Added algorithm metadata to connect visual behavior with theoretical complexity
- Added comparison and swap/write counters to make the tool useful for algorithm analysis, not just animation
- Add Heap Sort visualization
- Add graph algorithms (BFS, DFS, Dijkstra)
- Add pause / resume controls
- Add runtime benchmarking
- Add side-by-side comparison between algorithms