Skip to content

willhammondhimself/algo-explorer

Repository files navigation

Algo Explorer

Team

Will Hammond, David Aguinada, Kai Yeung

About

A PyQt5 app for visualizing data structures. We made this for our CSCI046 data structures and algorithms class because I (Will) kept getting confused by BST visualizations and pointer operations in the lecture slides. We wanted to actually see what happens step by step, so I built this visualizer. Turns out it helps a lot for understanding how the slow/fast pointer trick works for finding the middle of a linked list too.

What We Learned

This project really helped us understand data structures beyond just memorizing operations for exams:

  • BST Deletion is Tricky: The two-child case (finding the in-order successor) took way longer to debug than we expected. Drawing it out on paper first would've saved us hours.

  • PyQt Event Loop: Getting the canvas to update smoothly with data structure changes was harder than expected. Had to learn about signals/slots and when to call update() vs repaint().

  • Slow/Fast Pointers Actually Work: Seeing the algorithm run visually made it click way better than reading pseudocode. The fast pointer really does catch up at the middle!

  • Testing Finds Bugs: Writing comprehensive tests caught edge cases we never would've thought of (like the empty stack issue we fixed early on).

  • UI Takes Longer Than You Think: We spent probably 40% of our time on making the visualization look decent and handle user input properly.

What It Does

  • Stack - Push, pop, peek. Also has a recursive reverse function
  • Queue - Basic FIFO queue, plus a challenge to implement it using two stacks
  • Linked List - Insert/delete/search, with the slow/fast pointer algorithm for finding middle
  • BST - Insert, delete (all three cases), search, and tree traversals

Everything draws on a canvas so you can see the operations happening. You can zoom/pan if the tree gets big.

Running It

pip install -r requirements.txt
python main.py

You need Python 3.7+ and PyQt5.

Tests

There are some unit tests in the tests/ folder. Run them with:

pip install pytest
pytest

We tried to cover the main cases and edge cases for each data structure.

Jupyter Notebooks

We also made some Jupyter notebooks in the notebooks/ folder that walk through each data structure with examples and complexity explanations. They're useful if you want to play around with the code interactively.

pip install jupyter
jupyter notebook notebooks/

Challenge Mode

Each data structure has a challenge problem:

  • Stack: Reverse using recursion
  • Queue: Implement queue with two stacks
  • Linked List: Find middle in one pass
  • BST: Build balanced tree from sorted array

Click "Start Challenge" in the app to try them.

How It Works

The code is organized into:

  • data_structures/ - The actual stack, queue, linked list, and BST implementations
  • ui/ - PyQt5 interface stuff
  • visuals/ - Drawing logic for each data structure
  • challenges/ - Challenge mode logic
  • tests/ - Unit tests

We used the Command pattern for undo/redo (Ctrl+Z/Ctrl+Y work).

Known Issues

  • The zoom is kinda jumpy on trackpads sometimes
  • Challenge mode button throws an error on first click (have to click twice) - FIXED
  • Tree layout gets cramped if you insert like 20+ nodes
  • Would be cool to add graph algorithms (Dijkstra, BFS) next

Keyboard Shortcuts

  • Ctrl+Z - Undo
  • Ctrl+Y - Redo
  • Ctrl+Q - Quit

Built with Python and PyQt5 for CSCI046.

About

Visual Learning Tool for DS&A

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •