Skip to content

Repository files navigation

Sorting Algorithms Visualizer - PyQt Desktop Application

A beautiful desktop application built with PyQt for visualizing sorting algorithms step-by-step with interactive controls.

🖥️ Desktop Application Features

  • 🎯 5 Sorting Algorithms:

    • Bubble Sort
    • Quick Sort
    • Merge Sort
    • Insertion Sort
    • Selection Sort
  • 🎮 Interactive Desktop Controls:

    • ▶️ Play/Pause - Watch the animation or pause it
    • ➡️ Step Forward - Move to next step
    • ⬅️ Step Back - Move to previous step
    • ⏮️ Reset - Start over
    • ⏭️ Go to End - Jump to final result
    • 🎚️ Speed Control - Adjust animation speed with slider
    • 📏 Array Size - Change the number of elements to sort
    • 🎲 Generate New Array - Create random arrays to sort
  • 📊 Rich Visual Feedback:

    • Blue bars: Unsorted elements
    • Orange bars: Elements being compared
    • Red bars: Elements being swapped/moved
    • Green bars: Elements in their final sorted position
    • Real-time statistics: Comparisons, Swaps, Current Step
    • Algorithm complexity information
    • Progress tracking
  • 🎨 Modern PyQt Interface:

    • Native desktop application
    • Responsive bar chart visualization
    • Control panel with buttons and sliders
    • Color-coded legend
    • Algorithm selection dropdown
    • Real-time performance metrics

Requirements

  • Python 3.7 or higher
  • PyQt6 or PySide6
  • numpy

Installation

  1. Clone or download this project

  2. Install dependencies:

    pip install -r requirements.txt

Usage

Run the PyQt desktop application:

python3 pyqt_visual.py

How to Use:

  1. Select an algorithm from the dropdown menu at the top
  2. Adjust array size using the "Array Size" slider
  3. Click "Generate New Array" to create a new random array
  4. Control the visualization:
    • Click "Play" to start the animation (button changes to "Pause")
    • Click "Pause" to stop the animation
    • Click "Step Forward" to advance one step at a time
    • Click "Step Back" to review previous steps
    • Click "Reset" to start over
    • Click "Go to End" to see the final sorted array
  5. Adjust speed using the "Speed" slider
  6. View statistics - Comparisons, swaps, and current step are displayed in real-time

Project Structure

sorting-visualizer/
├── pyqt_visual.py         # PyQt desktop application (MAIN)
├── requirements.txt       # Python dependencies
├── README.md             # This file
├── algorithms/           # Sorting algorithm implementations
│   ├── __init__.py
│   ├── bubble_sort.py
│   ├── quick_sort.py
│   ├── merge_sort.py
│   ├── insertion_sort.py
│   └── selection_sort.py
└── tests/                # Unit tests for algorithms
    ├── test_bubble_sort.py
    ├── test_insertion_sort.py
    ├── test_merge_sort.py
    ├── test_quick_sort.py
    └── test_selection_sort.py

Algorithm Complexity

Algorithm Time (Best) Time (Average) Time (Worst) Space
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)

Customization

  • Change color scheme: Edit the color constants in pyqt_visual.py
  • Add new algorithms: Create a new file in algorithms/ following the generator pattern
  • Modify UI layout: Update the PyQt widget layout in pyqt_visual.py
  • Adjust visualization: Modify the bar chart drawing logic

Testing

Run unit tests to verify algorithm correctness:

python3 -m pytest tests/

Or run tests individually:

python3 -m pytest tests/test_quick_sort.py -v

Video link: https://drive.google.com/file/d/10-eOmClBH2gLHRrKiFRDyx_jP0pQijCA/view?usp=drive_link

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages