Skip to content

A professional-grade educational tool that transforms sorting algorithms into stunning real-time visualizations with interactive controls, multiple themes, and recording capabilities - perfect for students, educators, and developers to understand algorithmic concepts through beautiful animations.

License

Notifications You must be signed in to change notification settings

MUHAMMEDHAFEEZ/Algorithm-Visualizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฏ Advanced Sorting Algorithm Visualizer

A modern, interactive visualization tool for understanding sorting algorithms through beautiful animations and real-time statistics.

Python Pygame License

โœจ Features

Visual Demo

bubble_sort insertion_sort merge_sort quick_sort

๐Ÿ”ง Sorting Algorithms

  • Bubble Sort - Simple comparison-based algorithm
  • Insertion Sort - Efficient for small datasets
  • Selection Sort - In-place comparison sorting
  • Merge Sort - Divide and conquer approach
  • Quick Sort - Efficient divide and conquer
  • Heap Sort - Binary heap-based sorting

๐ŸŽจ Visual Features

  • Multiple Themes: Dark, Light, and Neon themes
  • Real-time Statistics: Comparisons, swaps, array accesses, and timing
  • Color-coded Elements: Different colors for comparing, swapping, and sorted elements
  • Smooth Animations: Fluid transitions and visual feedback
  • Responsive Design: Adaptive layout for different screen sizes

โšก Interactive Controls

  • Speed Control: Adjustable animation speed (1-10)
  • Step Mode: Step through algorithms one operation at a time
  • Direction Control: Ascending or descending sort
  • Array Size: Dynamic array sizing (10-200 elements)
  • Data Distributions: Random, sorted, reverse, and nearly sorted arrays

๐ŸŽฌ Recording & Export

  • Frame Recording: Capture every frame of the sorting process
  • GIF Creation: Automatically generate animated GIFs
  • Video Export: Convert frames to MP4 videos with ffmpeg
  • Batch Processing: Record all algorithms automatically
  • High Quality: Professional-grade output for presentations

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.7 or higher
  • pip package manager

Installation

  1. Clone the repository:

    https://github.com/MUHAMMEDHAFEEZ/Algorithm-Visualizer.git
    cd Algorithm-Visualizer
  2. Install dependencies:

    pip install -r requirements.txt
  3. Run the application:

    python main.py

๐ŸŽฌ Recording Demonstrations

Quick Recording

# Record all algorithms with frame capture
python demo.py --record

# Record and create GIFs automatically
python demo.py --record --gif

# Ultra-fast demo mode (smaller arrays, faster execution)
python demo.py --express

# Express mode with recording
python demo.py --express --record

# Use the interactive recording script
./record.sh          # macOS/Linux
record.bat           # Windows

Video Creation

# Install ffmpeg first
brew install ffmpeg  # macOS
# sudo apt install ffmpeg  # Linux

# Create MP4 from recorded frames
ffmpeg -framerate 30 -i recordings/bubble_sort/frame_%06d.png \
       -c:v libx264 -pix_fmt yuv420p bubble_sort.mp4

Recording Features

  • Automatic Frame Capture: Every animation frame saved as PNG
  • GIF Generation: Animated GIFs with optimized size
  • Video Export: High-quality MP4 videos via ffmpeg
  • Batch Processing: Record all algorithms in sequence
  • Professional Quality: Perfect for presentations and education
  • Speed Modes: Express mode for quick demos, normal mode for detailed viewing

See RECORDING_GUIDE.md for detailed instructions.

๐ŸŽฎ Controls

Basic Controls

Key Action
SPACE Start/Pause sorting
R Reset array with new random values
A Set to ascending order
D Set to descending order
T Cycle through themes
S Toggle step mode
ESC Exit application

Algorithm Selection

Key Algorithm
1 Bubble Sort
2 Insertion Sort
3 Selection Sort
4 Merge Sort
5 Quick Sort
6 Heap Sort

Speed & Size Control

Key Action
โ†‘ Increase speed
โ†“ Decrease speed
+ Increase array size
- Decrease array size

Data Distribution

Key Distribution
F1 Random array
F2 Sorted array
F3 Reverse sorted array
F4 Nearly sorted array

๐Ÿ› ๏ธ Technical Details

Architecture

The application follows a clean, modular architecture:

  • DrawInformation: Handles rendering and visual state management
  • SortingStats: Tracks algorithm performance metrics
  • ColorScheme: Manages theme-based color palettes
  • Algorithm Functions: Generator-based implementations for smooth visualization

Performance Optimization

  • Generator-based sorting: Allows for smooth step-by-step visualization
  • Efficient rendering: Only updates necessary screen regions
  • Adaptive frame rates: Adjusts based on sorting speed settings

Color Coding System

  • ๐Ÿ”ต Blue/Primary: Default elements
  • ๐ŸŸก Yellow/Comparing: Elements being compared
  • ๐Ÿ”ด Red/Swapping: Elements being swapped
  • ๐ŸŸข Green/Sorted: Elements in final position
  • ๐ŸŸฃ Purple/Current: Current element being processed

๐Ÿ“Š Algorithm Complexity

Algorithm Time Complexity (Best/Average/Worst) Space Complexity
Bubble Sort O(n) / O(nยฒ) / O(nยฒ) O(1)
Insertion Sort O(n) / O(nยฒ) / O(nยฒ) O(1)
Selection Sort O(nยฒ) / O(nยฒ) / O(nยฒ) O(1)
Merge Sort O(n log n) / O(n log n) / O(n log n) O(n)
Quick Sort O(n log n) / O(n log n) / O(nยฒ) O(log n)
Heap Sort O(n log n) / O(n log n) / O(n log n) O(1)

๐ŸŽจ Themes

Dark Theme

  • Modern dark interface with high contrast
  • Ideal for extended viewing sessions
  • Professional appearance

Light Theme

  • Clean, minimalist design
  • Easy on the eyes in bright environments
  • Classic and accessible

Neon Theme

  • Vibrant, eye-catching colors
  • Cyberpunk-inspired aesthetic
  • Great for demonstrations

๐Ÿ”ง Customization

Adding New Algorithms

To add a new sorting algorithm:

  1. Create a generator function following the pattern:

    def your_sort(draw_info: DrawInformation, ascending: bool = True) -> Generator[bool, None, None]:
        # Your sorting logic here
        # Use yield True to pause for visualization
        # Update draw_info.stats for metrics
  2. Add it to the algorithms dictionary in main()

  3. Assign a key binding for selection

Modifying Themes

Edit the ColorScheme.get_theme() method to customize colors or add new themes.

๐Ÿ“ˆ Educational Value

This visualizer is perfect for:

  • Computer Science Education: Understanding algorithm behavior
  • Interview Preparation: Visualizing common sorting algorithms
  • Research: Comparing algorithm performance
  • Presentations: Demonstrating sorting concepts

๐Ÿค 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

Areas for Contribution

  • Additional sorting algorithms (Radix, Counting, etc.)
  • Sound effects and audio feedback
  • Export functionality (GIF, video)
  • Performance benchmarking tools
  • Mobile/web version

๐Ÿ“ License

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

๐Ÿ™ Acknowledgments

  • Pygame Community for the excellent graphics library
  • Algorithm Visualizer projects for inspiration
  • Computer Science educators for algorithm explanations

๐Ÿ“ž Support

If you encounter any issues or have questions:

  • Open an issue on GitHub
  • Check the documentation

Made with โค๏ธ for computer science education and algorithm visualization BY HAFEEZ

About

A professional-grade educational tool that transforms sorting algorithms into stunning real-time visualizations with interactive controls, multiple themes, and recording capabilities - perfect for students, educators, and developers to understand algorithmic concepts through beautiful animations.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published