An educational desktop GUI application built with Python and Tkinter that visually demonstrates the step-by-step execution of sorting algorithms (Quicksort and Mergesort) and Binary Search.
- Visual Algorithm Demonstration: Watch algorithms execute step-by-step with color-coded visualizations
- Two Sorting Algorithms:
- Quicksort: See pivot selection, partitioning, and recursive sorting
- Mergesort: Observe array division and merging phases
- Binary Search: Visualize the search space reduction in a sorted array
- Interactive Controls: Play, pause, step-through, and reset animations
- Customizable Arrays: Generate random arrays or input custom values
- Color-Coded States:
- 🔵 Default (Blue): Unsorted elements
- 🔴 Comparing (Red): Elements being compared
- 🟡 Pivot (Orange): Pivot element in Quicksort
- 🟢 Sorted (Green): Elements in final position
- 💚 Found (Bright Green): Target found in Binary Search
- 🟣 Searching (Purple): Current search range
- 🟠 Merging/Partitioning: Active regions during sorting
- Algorithm Complexity Display: Shows time and space complexity for each algorithm
- Step Counter: Track the number of operations performed
- Status Updates: Detailed descriptions of each step
- Speed Control: Adjustable animation speed (10ms to 2000ms)
- Modern UI: Dark and light theme support with consistent padding and modern styling
- Python 3.8 or higher
- Tkinter (included with Python)
- sv-ttk (for modern theming) -
pip install sv-ttk
- Clone or download this repository
- Ensure Python 3.8+ is installed on your system
- Install the required theme package:
pip install sv-ttk
-
Run the application:
python main.py
-
Generate or Load an Array:
- Use the spinbox to set array size (5-50 elements)
- Click "Generate Array" for random values
- Or enter comma-separated values and click "Load Custom"
-
Sorting Visualization:
- Select algorithm (Quicksort or Mergesort) from dropdown
- Click "Start Sorting"
- Use Play/Pause button or Step button for control
- Adjust speed with the slider
-
Binary Search:
- Ensure array is sorted (app will prompt if not, or sort first using the sorting algorithms)
- After sorting is complete, binary search will be automatically enabled
- Enter target value in the search field
- Click "Start Binary Search"
- Watch as the search space narrows
- You can perform multiple searches on the same sorted array
-
Animation Controls:
- Play/Pause: Toggle continuous animation
- Next Step: Execute one step at a time
- Reset: Stop animation and return to initial state
- Speed Slider: Control animation delay
- Theme Toggle: Switch between dark and light themes
CautareBinara/
│
├── main.py # Main application with GUI setup and event handling
├── algorithms.py # Generator-based algorithm implementations
├── visualizer.py # Canvas-based array visualization component
├── tests/ # Tests, debugging tools, and demonstration files
│ ├── test_algorithms.py # Unit tests for algorithm correctness
│ ├── demo.py # Interactive feature demonstration
│ ├── debug_visualizer.py # Visualizer debugging tool
│ ├── test_array_issue.py # Array size testing tool
│ └── README.md # Documentation for test files
└── README.md # This file
- Implementation: Lomuto partition scheme
- Visualization: Highlights pivot, shows partitioning process
- Complexity: O(n log n) average, O(n²) worst case
- Space: O(log n) for recursion stack
- Implementation: Classic divide-and-conquer approach
- Visualization: Shows division and merging phases
- Complexity: O(n log n) always
- Space: O(n) for temporary arrays
- Implementation: Iterative approach
- Visualization: Highlights search range and midpoint
- Complexity: O(log n)
- Space: O(1)
The application follows a modular design:
-
main.py:
- Main application class (
AlgorithmVisualizerApp) - GUI setup and event handling
- Animation control logic
- Main application class (
-
algorithms.py:
- Generator functions that yield algorithm states
- Each state contains array snapshot and metadata
- Enables smooth step-by-step visualization
-
visualizer.py:
ArrayVisualizerclass for canvas-based rendering- Handles bar drawing with dynamic scaling
- Color management for different states
This visualizer helps students and developers:
- Understand algorithm mechanics through visual representation
- Compare algorithm performance with step counters
- Learn complexity analysis with displayed Big O notation
- Debug implementations by stepping through execution
- Build intuition about how algorithms work on different inputs
- Array Size: Adjustable from 5 to 50 elements
- Value Range: Currently 1-100 (modifiable in code)
- Animation Speed: 10ms to 2000ms per step
- Theme: Toggle between dark and light themes
- Color Scheme: Automatically adjusts based on selected theme
- Consistent Padding: Standardized spacing throughout the interface
The project includes comprehensive tests and debugging tools in the tests/ folder:
- Run Unit Tests:
cd tests && python test_algorithms.py - View Feature Demo:
cd tests && python demo.py - Debug Visualization:
cd tests && python debug_visualizer.py
See tests/README.md for detailed information about each test file.
- Start Small: Use arrays of 5-10 elements to understand the basics
- Step Through: Use the "Next Step" button to follow each operation
- Compare Algorithms: Try the same array with different sorting algorithms
- Edge Cases: Test with already sorted, reverse sorted, and random arrays
- Binary Search Practice: Try finding different values to understand the search pattern
Potential improvements for extended learning:
- Additional algorithms (Bubble Sort, Heap Sort, etc.)
- Algorithm comparison mode (side-by-side)
- Performance statistics and graphs
- Export animation as GIF
- Sound effects for operations
- More detailed pseudocode display
This project is created for educational purposes. Feel free to use, modify, and distribute.
- Window doesn't appear: Ensure Tkinter is properly installed with Python
- Animations too fast/slow: Adjust the speed slider
- Array too large: Maximum size is 50 for optimal visualization
- Binary Search not working: Array must be sorted first
Note: This visualizer is designed for learning and understanding algorithms. The implementations prioritize clarity and visualization over performance optimization.