A comprehensive Python application built with Tkinter that provides interactive visualizations of core algorithms and data structures. The visualizer features smooth 60 FPS animations, real-time complexity tracking, and educational pseudocode display.
- Binary Search - Efficient search in sorted arrays with step-by-step pointer tracking
- Bubble Sort - Classic sorting algorithm with swap animations and early termination detection
- Quick Sort - Divide-and-conquer sorting with pivot highlighting and partition visualization
- Dijkstra's Algorithm - Shortest path finding with distance updates and path reconstruction
- BFS Maze Solver - Breadth-first search for maze solving with path tracking
- Smooth 60 FPS Animations - Optimized canvas updates with double buffering
- Real-time Complexity Counters - Live tracking of comparisons, swaps, and visits
- Speed Control - Adjustable animation speed from 1-100 steps per second
- Interactive Controls - Pause, resume, reset, and step-through functionality
- Data Generation - Random, sorted, and reverse-sorted data options
- Pseudocode Display - Real-time algorithm pseudocode with current line highlighting
- Complexity Analysis - Big O notation display for time and space complexity
- Keyboard Shortcuts - Quick access to common functions
- Python 3.7 or higher
- Tkinter (usually included with Python)
- NumPy (for mathematical operations)
- Matplotlib (for advanced visualizations)
-
Clone the repository:
git clone <repository-url> cd Python-algorithm-visualizer
-
Install dependencies:
pip install -r requirements.txt
-
Run the application:
python main.py
numpy>=1.21.0
matplotlib>=3.5.0
- Launch the application using
python main.py
- Select an algorithm from the dropdown menu
- Choose your data size (10-1000 elements)
- Select data type (Random, Sorted, Reverse Sorted)
- Click "Generate Data" to create the dataset
- Use "Start" to begin the visualization
- Space - Toggle pause/resume
- Enter - Start algorithm
- Escape - Reset to initial state
- R - Reset algorithm
- P - Pause algorithm
- S - Start algorithm
- Ensure data is sorted (automatically handled)
- Set a target value to search for
- Watch as the algorithm narrows down the search space
- Adjust array size to see performance differences
- Try different data types to observe best/worst case scenarios
- Monitor comparison and swap counters
- Generate a grid with obstacles and weights
- Adjust grid size for different complexity levels
- Observe pathfinding in real-time
The application follows a clean Model-View-Controller architecture:
sorting.py
- Bubble sort and Quick sort implementationssearching.py
- Binary search implementationgraph.py
- Dijkstra and BFS implementations
Each algorithm is implemented as a generator function that yields step-by-step visualization data.
control_panel.py
- User interface controls and data generationcanvas_manager.py
- Main visualization canvas managementbase_visualizer.py
- Abstract base class for all visualizerssort_visualizer.py
- Specialized visualizer for sorting algorithmssearch_visualizer.py
- Specialized visualizer for searching algorithmsgraph_visualizer.py
- Specialized visualizer for graph algorithms
AlgorithmVisualizer
- Main application class coordinating between model and view- Handles user interactions and algorithm execution
- Manages animation timing and state transitions
Time Complexity: O(log n)
Space Complexity: O(1)
The binary search algorithm efficiently finds a target value in a sorted array by repeatedly dividing the search space in half. The visualization shows:
- Left and right boundary pointers
- Mid-point calculation
- Eliminated sections (grayed out)
- Target found highlighting
Time Complexity: O(n²) average, O(n) best case
Space Complexity: O(1)
Bubble sort repeatedly steps through the list, comparing adjacent elements and swapping them if they are in the wrong order. Features:
- Adjacent element comparison highlighting
- Swap animations with color changes
- Early termination detection
- Sorted portion highlighting
Time Complexity: O(n log n) average, O(n²) worst case
Space Complexity: O(log n) average, O(n) worst case
Quick sort uses a divide-and-conquer approach with pivot selection and partitioning. Visualization includes:
- Pivot selection (red highlighting)
- Partition boundary tracking
- Recursive subarray visualization
- Swap animations during partitioning
Time Complexity: O((V + E) log V)
Space Complexity: O(V)
Dijkstra's algorithm finds the shortest path in a weighted graph using a priority queue. Shows:
- Distance updates in real-time
- Visited nodes highlighting
- Current node exploration
- Shortest path reconstruction
Time Complexity: O(V + E)
Space Complexity: O(V)
Breadth-first search explores all neighbors at the current level before moving to the next level. Features:
- Level-by-level exploration
- Queue visualization
- Path reconstruction
- Visited node tracking
- Works with weighted grids (values 1-9)
- Intelligent grid generation ensures valid paths always exist
- Double Buffering: All drawing operations use double buffering to prevent flickering
- Selective Redraw: Only necessary elements are redrawn between frames
- Color Caching: Pre-computed color gradients for smooth transitions
- Generator-based Algorithms: Each algorithm yields step-by-step data for smooth visualization
- Configurable Speed: Animation speed can be adjusted from 1-100 steps per second
- State Management: Proper pause/resume/reset functionality with state preservation
- Efficient Data Structures: Algorithms use space-efficient implementations
- Garbage Collection: Proper cleanup of animation timers and generators
- Resource Pooling: Reuse of visualization objects where possible
This visualizer helps students understand:
- Algorithm Efficiency: Real-time complexity tracking shows the difference between O(n), O(n log n), and O(n²) algorithms
- Search Strategies: Binary search demonstrates the power of divide-and-conquer
- Sorting Techniques: Comparison between simple (bubble sort) and efficient (quick sort) algorithms
- Graph Algorithms: Pathfinding algorithms with different strategies (BFS vs Dijkstra)
- Space-Time Tradeoffs: Visual representation of memory usage vs execution time
- Understanding of Big O notation through visual complexity tracking
- Grasp of algorithm design patterns (divide-and-conquer, greedy, etc.)
- Appreciation for algorithm efficiency in real-world applications
- Hands-on experience with data structure operations
Algorithm | Time Complexity | Space Complexity | Best Case | Worst Case |
---|---|---|---|---|
Binary Search | O(log n) | O(1) | O(1) | O(log n) |
Bubble Sort | O(n²) | O(1) | O(n) | O(n²) |
Quick Sort | O(n log n) | O(log n) | O(n log n) | O(n²) |
Dijkstra | O((V+E) log V) | O(V) | O((V+E) log V) | O((V+E) log V) |
BFS | O(V + E) | O(V) | O(V + E) | O(V + E) |
Binary search algorithm showing left/right pointers, mid-point calculation, and eliminated sections in gray
Bubble sort with swap animations, comparison highlighting, and sorted portion indication
Quick sort showing pivot selection (red), partition boundaries, and recursive subarray visualization
Dijkstra's shortest path algorithm with distance updates, visited nodes, and optimal path reconstruction
BFS maze solver with level-by-level exploration, queue visualization, and path tracking
- Operating System: Windows 10+, macOS 10.14+, or Linux
- Python Version: 3.7 or higher
- Memory: 512 MB RAM minimum, 1 GB recommended
- Display: 1024x768 minimum resolution
- Animation Frame Rate: 60 FPS target
- Maximum Array Size: 1000 elements
- Maximum Grid Size: 20x20 cells
- Memory Usage: < 100 MB typical