Skip to content
AmirmasoudCSPublic

About

Interactive desktop application for visualizing data structures and algorithms with step-by-step, pausable, and rewindable animations using Python and Pygame.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

550 Commits

Folders and files

Repository files navigation

AlgoLab

A desktop application built with Python and Pygame for visualizing data structures and algorithms.

Each operation is presented as a step-by-step, pausable, rewindable animation, with a live explanation of what is happening. AlgoLab was developed as an educational companion for a Data Structures and Algorithms course.

πŸ“Έ Screenshots

Main Menu - Pick any of the nine topics to open its dedicated visualizer.

Stack - Push, pop, and peek animated step by step, with a live TOP pointer.

Queue - Enqueue and dequeue animated with FRONT and REAR pointers.

Linked List - Insert and delete operations, with HEAD and the algorithm's temporary PREVIOUS / CURRENT / NEW pointers shown as they move.

Binary Search Tree - Insert, search, delete, and traversals, rendered as a live tree diagram.

Heap - Min/Max heap operations shown as both a tree and its underlying array, side by side.

Graph - Build a custom directed/undirected, weighted/unweighted graph and run BFS, DFS, Dijkstra, or Bellman-Ford on it.

Sorting - Merge Sort visualized as an animated bar chart. Bubble, Selection, Insertion, Quick, and Heap Sort are also available on the same screen.

Sorting (race mode) - Race mode between Quick Sort and Merge Sort

Hash Table - Separate chaining collision resolution with a live load factor bar. Linear probing, quadratic probing, and double hashing are also supported.

Asymptotic Notation - Compare Big-O growth curves from O(1) to O(n^n) with an adjustable input size.

πŸ“š Topics

  • Asymptotic Notation: Complexity graphs with adjustable inputs
  • Linked Lists: Insert, delete, search
  • Stacks: Push, pop, peek
  • Queues: Enqueue, dequeue, peek
  • Binary Search Trees: Insert, search, delete, min/max, traversals
  • Heaps: Min/Max heaps, insert, peek, extract, heapify
  • Graphs: Directed/undirected, weighted/unweighted, BFS, DFS, Dijkstra, Bellman-Ford
  • Sorting: Bubble Sort, Insertion Sort, Merge Sort, Quick Sort, Heap Sort
  • Hash Tables & Sets: Chaining, probing, double hashing, Set/Map modes, configurable hash functions, collision counting

✨ Features

  • Step-by-step, pausable, and rewindable simulations

  • Adjustable animation speed

  • Live explanations of operations

  • Color-coded operations and legends

  • Configurable data structure attributes

  • Randomize button for every topic

  • Per-topic Big-O reference table through the Info button on every topic screen

  • Fullscreen, auto-scaled to the machine's native resolution

  • Screenshot capture (F12), saved to assets/screenshots/

  • Keyboard shortcuts:

    • P Pause/Resume
    • <- / -> Step backward/forward
    • Enter Run the primary action
    • F12 Take a screenshot
    • Esc Quit

βš™οΈ Getting Started

Requirements

  • Python 3.10+
  • Pygame

1. Clone the Repository

git clone https://github.com/AmirmasoudCS/AlgoLab.git
cd AlgoLab

2. Create a Virtual Environment

python -m venv .venv

3. Activate the Virtual Environment

Windows:

.venv\Scripts\activate

Linux / macOS:

source .venv/bin/activate

4. Install Dependencies

pip install -r requirements.txt

Run the Application

Run from the source:

python -m algolab.main

Build a standalone application:

AlgoLab can also be packaged as a standalone executable using PyInstaller.

pyinstaller AlgoLab.spec

The packaged application will be available in the dist/ directory.

πŸ—οΈ Architecture

Each topic follows the same structure:

model.py        # Data structure and state
operations.py   # Operations performed on the structure
simulation.py   # Step-by-step simulation

Simulations operate on a copy of the model's state and record each intermediate state as an immutable snapshot. The real model is only updated when the simulation completes.

This allows operations to be paused, replayed, rewound, and committed without modifying the actual data structure during the animation.

Randomize actions bypass the simulation layer and use the data structure's normal operations to produce an immediate state.

πŸ“ Project Structure

πŸ“ 
β”œβ”€β”€ πŸ“ assets
β”‚   β”œβ”€β”€ πŸ“ screenshots
β”‚   β”‚   β”œβ”€β”€ πŸ–ΌοΈ asymptotic.png
β”‚   β”‚   β”œβ”€β”€ πŸ–ΌοΈ bst.png
β”‚   β”‚   β”œβ”€β”€ πŸ–ΌοΈ graph.png
β”‚   β”‚   β”œβ”€β”€ πŸ–ΌοΈ hash_chaing.png
β”‚   β”‚   β”œβ”€β”€ πŸ–ΌοΈ heap.png
β”‚   β”‚   β”œβ”€β”€ πŸ–ΌοΈ linked_list.png
β”‚   β”‚   β”œβ”€β”€ πŸ–ΌοΈ main_menu.png
β”‚   β”‚   β”œβ”€β”€ πŸ–ΌοΈ merge_sort.png
β”‚   β”‚   β”œβ”€β”€ πŸ–ΌοΈ queue.png
β”‚   β”‚   └── πŸ–ΌοΈ stack.png
β”‚   β”œβ”€β”€ πŸ“„ icon.ico
β”‚   └── πŸ–ΌοΈ icon.png
β”œβ”€β”€ πŸ“ config
β”‚   └── βš™οΈ config.toml
β”œβ”€β”€ πŸ“ log
β”œβ”€β”€ πŸ“ src
β”‚   └── πŸ“ algolab
β”‚       β”œβ”€β”€ πŸ“ core
β”‚       β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚       β”‚   β”œβ”€β”€ 🐍 application.py
β”‚       β”‚   └── 🐍 configuration.py
β”‚       β”œβ”€β”€ πŸ“ simulation
β”‚       β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚       β”‚   β”œβ”€β”€ 🐍 events.py
β”‚       β”‚   β”œβ”€β”€ 🐍 history.py
β”‚       β”‚   β”œβ”€β”€ 🐍 simulator.py
β”‚       β”‚   └── 🐍 state.py
β”‚       β”œβ”€β”€ πŸ“ topics
β”‚       β”‚   β”œβ”€β”€ πŸ“ asymptotic
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 complexity.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 model.py
β”‚       β”‚   β”‚   └── 🐍 visualizer.py
β”‚       β”‚   β”œβ”€β”€ πŸ“ bst
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 model.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 operations.py
β”‚       β”‚   β”‚   └── 🐍 simulation.py
β”‚       β”‚   β”œβ”€β”€ πŸ“ graph
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 model.py
β”‚       β”‚   β”‚   └── 🐍 simulation.py
β”‚       β”‚   β”œβ”€β”€ πŸ“ hash_table
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 model.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 operations.py
β”‚       β”‚   β”‚   └── 🐍 simulation.py
β”‚       β”‚   β”œβ”€β”€ πŸ“ heap
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 model.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 operations.py
β”‚       β”‚   β”‚   └── 🐍 simulation.py
β”‚       β”‚   β”œβ”€β”€ πŸ“ linked_list
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 model.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 operations.py
β”‚       β”‚   β”‚   └── 🐍 simulation.py
β”‚       β”‚   β”œβ”€β”€ πŸ“ queue
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 model.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 operations.py
β”‚       β”‚   β”‚   └── 🐍 simulation.py
β”‚       β”‚   β”œβ”€β”€ πŸ“ sorting
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 model.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 operations.py
β”‚       β”‚   β”‚   └── 🐍 simulation.py
β”‚       β”‚   β”œβ”€β”€ πŸ“ stack
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 model.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 operations.py
β”‚       β”‚   β”‚   └── 🐍 simulation.py
β”‚       β”‚   └── 🐍 __init__.py
β”‚       β”œβ”€β”€ πŸ“ ui
β”‚       β”‚   β”œβ”€β”€ πŸ“ components
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 button.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 checkbox.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 info_panel.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 numeric_input.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 radio_button.py
β”‚       β”‚   β”‚   └── 🐍 surface.py
β”‚       β”‚   β”œβ”€β”€ πŸ“ screens
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 asymptotic.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 bst.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 graph.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 hash_table.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 heap.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 linked_list.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 main_menu.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 queue.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 screen.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 screen_manager.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 sorting.py
β”‚       β”‚   β”‚   └── 🐍 stack.py
β”‚       β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚       β”‚   └── 🐍 theme.py
β”‚       β”œβ”€β”€ πŸ“ visualization
β”‚       β”‚   β”œβ”€β”€ πŸ“ graph
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 bounds.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 coordinate_system.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 curve.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 layout.py
β”‚       β”‚   β”‚   β”œβ”€β”€ 🐍 renderer.py
β”‚       β”‚   β”‚   └── 🐍 scaling.py
β”‚       β”‚   └── 🐍 __init__.py
β”‚       β”œβ”€β”€ 🐍 __init__.py
β”‚       └── 🐍 main.py
β”œβ”€β”€ πŸ“ tests
β”‚   β”œβ”€β”€ πŸ“ core
β”‚   β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚   β”‚   └── 🐍 test_configuration.py
β”‚   β”œβ”€β”€ πŸ“ simulation
β”‚   β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚   β”‚   β”œβ”€β”€ 🐍 test_events.py
β”‚   β”‚   β”œβ”€β”€ 🐍 test_history.py
β”‚   β”‚   β”œβ”€β”€ 🐍 test_simulator.py
β”‚   β”‚   └── 🐍 test_state.py
β”‚   β”œβ”€β”€ πŸ“ topics
β”‚   β”‚   β”œβ”€β”€ πŸ“ asymptotic
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_complexity.py
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_model.py
β”‚   β”‚   β”‚   └── 🐍 test_visualizer.py
β”‚   β”‚   β”œβ”€β”€ πŸ“ bst
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_bst_model.py
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_bst_operations.py
β”‚   β”‚   β”‚   └── 🐍 test_bst_simulation.py
β”‚   β”‚   β”œβ”€β”€ πŸ“ heap
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_heap_model.py
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_heap_operations.py
β”‚   β”‚   β”‚   └── 🐍 test_heap_simulation.py
β”‚   β”‚   β”œβ”€β”€ πŸ“ linked_list
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_linked_list_model.py
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_operations.py
β”‚   β”‚   β”‚   └── 🐍 test_simulation.py
β”‚   β”‚   β”œβ”€β”€ πŸ“ queue
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_queue_model.py
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_queue_operations.py
β”‚   β”‚   β”‚   └── 🐍 test_queue_simulation.py
β”‚   β”‚   β”œβ”€β”€ πŸ“ stack
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_stack_model.py
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_stack_operations.py
β”‚   β”‚   β”‚   └── 🐍 test_stack_simulation.py
β”‚   β”‚   └── 🐍 __init__.py
β”‚   β”œβ”€β”€ πŸ“ ui
β”‚   β”‚   β”œβ”€β”€ πŸ“ compontets
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 checkbox.py
β”‚   β”‚   β”‚   └── 🐍 radio_button.py
β”‚   β”‚   β”œβ”€β”€ πŸ“ screens
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_asymptotic.py
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_main_menu.py
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_screen.py
β”‚   β”‚   β”‚   └── 🐍 test_screen_manager.py
β”‚   β”‚   └── 🐍 __init__.py
β”‚   β”œβ”€β”€ πŸ“ visualization
β”‚   β”‚   β”œβ”€β”€ πŸ“ graph
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 __init__.py
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_bounds.py
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_coordinate_system.py
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_curve.py
β”‚   β”‚   β”‚   β”œβ”€β”€ 🐍 test_layout.py
β”‚   β”‚   β”‚   └── 🐍 test_scaling.py
β”‚   β”‚   └── 🐍 __init__.py
β”‚   └── 🐍 __init__.py
β”œβ”€β”€ πŸ“„ AlgoLab.spec
β”œβ”€β”€ βš–οΈ LICENSE
β”œβ”€β”€ βš™οΈ pyproject.toml
β”œβ”€β”€ πŸ“˜ README.md
β”œβ”€β”€ πŸ“ requirements.txt
└── 🐍 smoke_test.py

Generated using Tree Printer

πŸ§ͺ Testing

AlgoLab uses pytest for automated testing.

pytest

Tests cover the core logic, simulation system, data structure operations, UI components, and visualization utilities.

⚠️ Known Limitations

  • BST Randomization can produce highly skewed trees depending on insertion order.
  • Heap Type Switching rebuilds the heap when switching between Min and Max modes.
  • Hash Tables do not automatically resize when an open-addressing table becomes full.
  • Queue's dequeue is O(n) in this implementation (list.pop(0)), not the textbook O(1). A deque- or linked-list-backed queue would achieve O(1).

βš–οΈ License

This project is licensed under the MIT License.

About

Interactive desktop application for visualizing data structures and algorithms with step-by-step, pausable, and rewindable animations using Python and Pygame.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages