Interactive visualization of sorting and searching algorithms built with PHP, MySQL, and JavaScript
| Feature | Description |
|---|---|
| ๐ฏ Multiple Algorithms | Bubble Sort, Quick Sort, Merge Sort, and Binary Search |
| ๐จ Interactive Visualization | Real-time animated bar charts showing algorithm execution |
| โฏ๏ธ Playback Controls | Play, Pause, Reset with adjustable speed (100ms - 1000ms) |
| ๐ฎ Keyboard Shortcuts | Press Space to toggle play/pause |
| ๐ Step-by-Step Tracking | Watch each comparison and swap in detail |
| ๐ Search Support | Binary Search with target value input |
| ๐พ Database Persistence | All steps stored in MySQL for review |
| ๐ฑ Responsive Design | Works on desktop and mobile devices |
| ๐จ Modern UI | Clean, colorful, and user-friendly interface |
- PHP 7.4 or higher
- MySQL 5.7 or higher
- Web server (Apache/Nginx) or XAMPP/WAMP/MAMP
- Composer (optional, for autoloader)
# 1. Clone the repository
git clone https://github.com/Bendz07/algorithm-visualizer.git
cd algorithm-visualizer
# 2. Set up the database
mysql -u root -p < database/schema.sql
# 3. Configure environment
cp .env.example .env
# Edit .env with your database credentials
# 4. Install dependencies (optional)
composer install
# 5. Start your web server
# For PHP built-in server:
php -S localhost:8000 -t public/
# For XAMPP/WAMP:
# Place the project in htdocs/www folderOpen your browser and navigate to:
http://localhost:8000/
or
http://localhost/algorithm-visualizer/public/
Select from the dropdown menu:
- Bubble Sort - Simple adjacent comparison sort
- Quick Sort - Divide and conquer with pivot
- Merge Sort - Recursive merge-based sorting
- Binary Search - Find target in sorted array
For Sorting:
[5, 3, 8, 1, 2, 7, 4, 6]For Binary Search:
[10, 20, 30, 40, 50, 60, 70, 80]Then enter a target value (e.g., 50)
| Button | Action |
|---|---|
| ๐ข Visualize | Generate algorithm steps |
| Start animation | |
| โธ๏ธ Pause | Pause animation |
| ๐ Reset | Go back to first step |
| ๐๏ธ Speed Slider | Adjust animation speed |
Bubble Sort - O(nยฒ) Time Complexity
- Compares adjacent elements and swaps if they're in wrong order
- Largest elements "bubble" to the end
- Visual: Red bars indicate comparisons/swaps
Quick Sort - O(n log n) Average
- Uses divide-and-conquer approach
- Selects a pivot and partitions around it
- Visual: Red bar shows pivot element
Merge Sort - O(n log n) Time
- Divides array into halves recursively
- Merges sorted sub-arrays
- Visual: Shows merging process
Binary Search - O(log n) Time
- Requires sorted array
- Repeatedly divides search space in half
- Visual: Red bar shows current middle element
algorithm-visualizer/
โโโ config/
โ โโโ database.php # Database configuration
โโโ public/ # Web root
โ โโโ index.php # Main entry point
โ โโโ css/
โ โ โโโ style.css # Stylesheets
โ โโโ js/
โ โโโ visualizer.js # Main visualization logic
โ โโโ api.js # API calls
โโโ src/
โ โโโ Controllers/
โ โ โโโ AlgorithmController.php
โ โ โโโ HomeController.php
โ โโโ Models/
โ โ โโโ StepModel.php
โ โ โโโ SessionModel.php
โ โโโ Algorithms/
โ โโโ AlgorithmInterface.php
โ โโโ BubbleSort.php
โ โโโ QuickSort.php
โ โโโ MergeSort.php
โ โโโ BinarySearch.php
โ โโโ SearchInterface.php
โโโ logs/ # Application logs
โโโ .env # Environment variables
โโโ composer.json # Composer dependencies
โโโ README.md # This file
CREATE TABLE algorithm_steps (
id INT AUTO_INCREMENT PRIMARY KEY,
session_id VARCHAR(36) NOT NULL,
step_number INT NOT NULL,
array_state TEXT NOT NULL,
active_indices TEXT,
message VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_session (session_id)
);| Key | Action |
|---|---|
Space |
Toggle Play/Pause |
Enter |
Start Visualization |
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Clone your fork
git clone https://github.com/Bendz07/algorithm-visualizer.git
# Install dependencies
composer install
# Run tests (if any)
phpunit
# Start development server
php -S localhost:8000 -t public/- Create a new class in
src/Algorithms/ - Implement the
AlgorithmInterface(for sorting) orSearchInterface(for searching) - Add your algorithm to the dropdown in
public/index.php - Update the controller's switch statement
Database Connection Error
- Ensure MySQL is running
- Check credentials in
.envfile - Verify database exists:
CREATE DATABASE algorithm_visualizer; - Run the SQL schema to create tables
Composer Autoloader Missing
- Run
composer installin the project root - Or use the manual autoloader (see
public/index.php)
Blank Page / No Visualization
- Check PHP error logs
- Enable error reporting:
error_reporting(E_ALL); ini_set('display_errors', 1); - Verify all files are in correct locations
- Check browser console for JavaScript errors
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by various algorithm visualization tools
- Built with โค๏ธ for the developer community
- Thanks to all contributors and open-source libraries
X and Gmail - @b_abdelali - abdel.contact@gmail.com
Project Link: https://github.com/Bendz07/algorithm-visualizer
Made with โค๏ธ and PHP
Features โข Quick Start โข Usage Guide โข Algorithms โข Contributing
Don't forget to โญ star this repository if you found it helpful!
