Skip to content

Bendz07/Algorithm-Visualizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿงฉ Algorithm Visualizer

Interactive visualization of sorting and searching algorithms built with PHP, MySQL, and JavaScript

PHP Version MySQL JavaScript License PRs Welcome


๐Ÿ“ธ Preview


โœจ Features

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

๐Ÿš€ Quick Start

Prerequisites

  • PHP 7.4 or higher
  • MySQL 5.7 or higher
  • Web server (Apache/Nginx) or XAMPP/WAMP/MAMP
  • Composer (optional, for autoloader)

Installation

# 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 folder

Quick Access

Open your browser and navigate to:

http://localhost:8000/

or

http://localhost/algorithm-visualizer/public/

๐ŸŽฏ Usage Guide

1๏ธโƒฃ Choose an Algorithm

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

2๏ธโƒฃ Enter Your Data

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)

3๏ธโƒฃ Visualize & Interact

Button Action
๐ŸŸข Visualize Generate algorithm steps
โ–ถ๏ธ Play Start animation
โธ๏ธ Pause Pause animation
๐Ÿ”„ Reset Go back to first step
๐ŸŽš๏ธ Speed Slider Adjust animation speed

๐Ÿงฎ Supported Algorithms

Sorting Algorithms

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

Search Algorithms

Binary Search - O(log n) Time
  • Requires sorted array
  • Repeatedly divides search space in half
  • Visual: Red bar shows current middle element

๐Ÿ—๏ธ Project Structure

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

๐Ÿ› ๏ธ Technology Stack

PHP MySQL JavaScript HTML5 CSS3 Canvas API


๐Ÿ“Š Database Schema

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)
);

๐ŸŽฎ Keyboard Shortcuts

Key Action
Space Toggle Play/Pause
Enter Start Visualization

๐Ÿค Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

# 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/

Adding New Algorithms

  1. Create a new class in src/Algorithms/
  2. Implement the AlgorithmInterface (for sorting) or SearchInterface (for searching)
  3. Add your algorithm to the dropdown in public/index.php
  4. Update the controller's switch statement

๐Ÿ› Troubleshooting

Database Connection Error
  • Ensure MySQL is running
  • Check credentials in .env file
  • Verify database exists: CREATE DATABASE algorithm_visualizer;
  • Run the SQL schema to create tables
Composer Autoloader Missing
  • Run composer install in 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

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments

  • Inspired by various algorithm visualization tools
  • Built with โค๏ธ for the developer community
  • Thanks to all contributors and open-source libraries

๐Ÿ“ฌ Contact

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


๐Ÿ“ธ Screenshots Gallery

Bubble Sort Quick Sort
Merge Sort Binary Search


โญ Star History

Star History Chart


Don't forget to โญ star this repository if you found it helpful!

About

Interactive visualization of sorting and searching algorithms built with PHP, MySQL, and JavaScript

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages