Will Hammond, David Aguinada, Kai Yeung
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.
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()vsrepaint(). -
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.
- 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.
pip install -r requirements.txt
python main.pyYou need Python 3.7+ and PyQt5.
There are some unit tests in the tests/ folder. Run them with:
pip install pytest
pytestWe tried to cover the main cases and edge cases for each data structure.
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/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.
The code is organized into:
data_structures/- The actual stack, queue, linked list, and BST implementationsui/- PyQt5 interface stuffvisuals/- Drawing logic for each data structurechallenges/- Challenge mode logictests/- Unit tests
We used the Command pattern for undo/redo (Ctrl+Z/Ctrl+Y work).
- 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
Ctrl+Z- UndoCtrl+Y- RedoCtrl+Q- Quit
Built with Python and PyQt5 for CSCI046.