A comprehensive Python application for visualizing multiple sorting algorithms with a unified interface.
- Unified GUI: Single application with algorithm selection
- Modular Architecture: Easy to add new algorithms
- Step-by-step Visualization: Watch algorithms work with detailed animations
- Multiple Control Options: Play, pause, step forward/backward through the sorting process
- Customizable Arrays: Generate random arrays or input your own data
- Speed Control: Adjust animation speed from very slow to very fast
- Save Functionality: Export visualizations as PNG, PDF, or SVG files
- Detailed Algorithm Information: View complexity and characteristics of each algorithm
- Time Complexity: Average O(n log n), Worst O(n²)
- Space Complexity: O(log n)
- Type: Divide and conquer algorithm
- Stability: Not stable
- Time Complexity: O(n²)
- Space Complexity: O(1)
- Best Case: O(n) - when array is already sorted
- Type: Simple comparison-based algorithm
- Stability: Stable
- Time Complexity: O(n²)
- Space Complexity: O(1)
- Best Case: O(n²) - always the same performance
- Type: Simple selection-based algorithm
- Stability: Not stable
- Time Complexity: O(n log n)
- Space Complexity: O(n)
- Best Case: O(n log n) - always consistent performance
- Type: Divide and conquer algorithm
- Stability: Stable
- Time Complexity: O(n²)
- Space Complexity: O(1)
- Best Case: O(n) - when array is already sorted
- Type: Incremental construction algorithm
- Stability: Stable
-
Clone the Repository:
git clone https://github.com/haydarkadioglu/sorting-algorithms cd sorting-algorithms
-
Install Required Dependencies:
pip install -r requirements.txt
python main_gui.py
- Select Algorithm: Choose from the dropdown menu
- Load Algorithm: Click "Load Algorithm" to initialize the selected algorithm
- Configure Array: Set size, generate random array, or input manual values
- Control Animation: Use play, pause, step controls
- View Information: Click "ℹ About" for algorithm details
- Generate New Array: Creates a new random array of specified size
- Manual Array: Input your own array values
- ▶ Start: Begin the sorting animation
- ⏸ Pause: Pause the current animation
- ↻ Reset: Reset to the original unsorted state
- ⏮ Previous / ⏭ Next: Step through the algorithm manually
- Speed Control: Adjust animation speed (Very Slow to Very Fast)
- 📊 Save: Export the current visualization
sorting-algorithms/
├── main_gui.py # Main application entry point
├── algorithms/ # Algorithm implementations
│ ├── __init__.py # Package initialization
│ ├── base_algorithm.py # Base class for all algorithms
│ └── quicksort.py # Quick Sort implementation
├── requirements.txt # Dependencies
└── README.md # Documentation
The application uses a modular architecture where:
- main_gui.py: Main application that discovers and loads algorithms
- base_algorithm.py: Abstract base class defining the algorithm interface
- Algorithm files: Individual implementations inheriting from the base class
To add a new sorting algorithm:
- Create a new file in the
algorithms/
directory - Inherit from
SortingAlgorithmBase
- Implement required methods:
create_gui()
: Create algorithm-specific GUIsort_algorithm()
: Implement the sorting logicadd_step()
: Define visualization stepsshow_current_step()
: Display current algorithm state
- Set algorithm metadata (name, complexity, etc.)
The main GUI will automatically discover and load the new algorithm.
- Python 3.x: Core language
- tkinter: GUI framework (usually comes with Python)
- matplotlib: Visualization and plotting
- numpy: Numerical operations and array handling
All algorithms inherit from SortingAlgorithmBase
which provides:
- Common array operations
- Animation control methods
- Step management
- Color scheme definitions
- GUI component standards
Quick Sort is a highly efficient divide-and-conquer algorithm that:
- Chooses a Pivot: Selects an element as the pivot (typically the last element)
- Partitions: Rearranges the array so elements smaller than pivot go left, larger go right
- Recursively Sorts: Applies the same process to the left and right subarrays
- Combines: The sorted subarrays naturally combine to form the final sorted array
Visualization Features:
- Color-coded elements (pivot, comparing, partitions)
- Step-by-step partition process
- Recursive call visualization
- Detailed status information
Bubble Sort is a simple comparison-based sorting algorithm that:
- Compares Adjacent Elements: Goes through the list comparing neighboring elements
- Swaps if Necessary: Swaps elements if they are in the wrong order
- Bubbles Up: Larger elements "bubble" to the end of the array
- Repeats Passes: Continues until no more swaps are needed
Visualization Features:
- Color-coded elements (comparing, swapping, sorted)
- Step-by-step comparison process
- Pass-by-pass visualization
- Early termination when sorted
Selection Sort is a simple comparison-based sorting algorithm that:
- Divides Array: Splits the array into sorted and unsorted parts
- Finds Minimum: Finds the smallest element in the unsorted part
- Swaps Elements: Swaps the minimum with the first unsorted element
- Moves Boundary: Expands the sorted part by one element
Visualization Features:
- Color-coded elements (current position, minimum, comparing, sorted)
- Step-by-step minimum finding process
- Clear boundary between sorted and unsorted parts
- Detailed comparison explanations
Merge Sort is an efficient divide-and-conquer algorithm that:
- Divides: Splits the array into two halves recursively
- Conquers: Sorts each half independently
- Combines: Merges the sorted halves back together
- Guarantees: Consistent O(n log n) performance in all cases
Visualization Features:
- Color-coded subarrays (left, right, merged)
- Step-by-step divide and conquer process
- Clear merge operation visualization
- Recursive call tracking
Insertion Sort is a simple and intuitive algorithm that:
- Starts Small: Considers the first element as sorted
- Takes Next Element: Picks the next unsorted element
- Finds Position: Compares and finds the correct insertion position
- Shifts Elements: Moves larger elements one position right
- Inserts: Places the element in its correct position
Visualization Features:
- Color-coded elements (current, comparing, shifting, sorted)
- Step-by-step insertion process
- Clear boundary between sorted and unsorted parts
- Detailed shifting visualization
Contributions are welcome! The modular architecture makes it easy to add new algorithms:
- Follow the base class interface
- Implement visualization steps
- Set algorithm metadata
- Test with the main GUI
- Bug fixes
- UI improvements
- Documentation enhancements
- Performance optimizations
This project is open source and available under the MIT License.
- Additional sorting algorithms (Heap Sort, Radix Sort, Shell Sort, etc.)
- Algorithm comparison mode
- Performance statistics
- Sound effects
- Custom themes
- Export animations
- Array generation patterns
- Educational content integration