Skip to content

About

Interactive sorting algorithm visualizer with real-time animations. Built with Python and Matplotlib

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

🇷🇺 Русская версия

Sorting Algorithm Visualizer

Python Matplotlib License

Interactive sorting algorithm visualizer with real-time animations

Description • Features • Installation • Usage • Algorithms


Description

An educational Python project that demonstrates how various sorting algorithms work through real-time interactive animations. The visualizer helps build intuition for algorithmic behavior by showing each comparison, swap, and merge step as it happens.

Features

  • Bubble Sort — simple algorithm with clear visualization of comparisons and swaps
  • Quick Sort — efficient divide-and-conquer algorithm with partition visualization
  • Merge Sort — stable algorithm showing the split-and-merge process
  • Interactive animation — step-by-step visualization of every algorithm operation
  • Color coding — active elements are highlighted during sorting
  • Configurable parameters — adjustable array size and animation speed

Installation

Prerequisites

  • Python 3.7+
  • pip

Setup

  1. Clone the repository:
git clone https://github.com/CHUKEPC/sorting_visualizer.git
cd sorting_visualizer
  1. Install dependencies:
pip install -r requirements.txt

Usage

Basic usage

Run the program and select an algorithm from the menu:

python sorting_visualizer.py

Programmatic usage

from sorting_visualizer import SortingVisualizer

# Create a visualizer with an array of 30 elements
visualizer = SortingVisualizer(size=30)

# Visualize Bubble Sort
visualizer.visualize(algorithm='bubble', speed=100)

# Visualize Quick Sort
visualizer.visualize(algorithm='quick', speed=100)

# Visualize Merge Sort
visualizer.visualize(algorithm='merge', speed=100)

Examples

Custom data

custom_data = [64, 34, 25, 12, 22, 11, 90, 5, 77, 88]
visualizer = SortingVisualizer(data=custom_data)
visualizer.visualize(algorithm='quick')

Adjusting animation speed

visualizer = SortingVisualizer(size=20)

# Fast animation (10 ms between frames)
visualizer.visualize(algorithm='bubble', speed=10)

# Slow animation (500 ms between frames)
visualizer.visualize(algorithm='bubble', speed=500)

Visualization Guide

  • Red bars — elements being compared or moved in the current step
  • Blue bars — remaining array elements
  • Green bars — final sorted state
  • Step counter — displays the current step number and total steps

Tech Stack

  • Python 3.7+
  • Matplotlib — chart rendering and animation
  • NumPy — array operations (optional)

Project Structure

sorting_visualizer/
├── sorting_visualizer.py   # Main module with classes and algorithms
├── requirements.txt        # Project dependencies
├── README.md               # Documentation (English)
├── README_RU.md            # Documentation (Russian)
├── .gitignore              # Git ignore rules
└── LICENSE                 # MIT License

API Reference

Class SortingVisualizer

Parameter Type Description Default
data List[int] Initial data array None
size int Array size (if data is not provided) 30

Method visualize()

Parameter Type Description Default
algorithm str Algorithm: 'bubble', 'quick', 'merge' 'bubble'
speed int Animation speed (ms between frames) 50

Sorting Algorithms

Bubble Sort

  • Time complexity: O(n²)
  • Stable: Yes
  • Notes: Simple to understand but slow for large arrays

Quick Sort

  • Time complexity: O(n log n) average, O(n²) worst case
  • Stable: No
  • Notes: One of the most efficient general-purpose sorting algorithms

Merge Sort

  • Time complexity: O(n log n)
  • Stable: Yes
  • Notes: Guaranteed O(n log n) performance, requires additional memory

Contributing

Contributions are welcome! To contribute:

  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

License

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

Author

CHUKEPC

About

Interactive sorting algorithm visualizer with real-time animations. Built with Python and Matplotlib

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages