Overview

Three data structures written from scratch in standard-library Python, each with a tab in a small desktop app that explains what it is doing as you use it.

Structure What you can do
Binary search tree Insert whole numbers; see the tree drawn and its in-order traversal
Hash table with separate chaining Insert keys and values; see which slot each lands in, and when two keys share one
Directed graph Add edges; see the adjacency list and the order a breadth-first search visits nodes

What I found when I came back to it

Reading the code again in November 2026, with tests this time, turned up five problems:

  • Breadth-first search crashed when an edge pointed to a higher-numbered node than any starting node. It kept visited nodes in a list sized by the largest source.
  • The hash table lost data. Keys whose hashes collide, such as “ab” and “ba”, overwrote each other silently.
  • The graph tab overwrote its own adjacency list with the search result, in a box still labelled “Adjacency List”.
  • Its search controls were cut off at the edge of the window, and it refused to search from a node that only appears as an edge’s target.
  • The tree tab only printed a sorted list. That hides the one thing a tree is for: its shape.

What changed

  • Breadth-first search uses a set and a deque, so it works for any node type in O(V + E).
  • Each hash slot holds a list of pairs, so colliding keys are both kept. The app now groups keys by slot, so a collision is visible.
  • The tree is drawn on a canvas, each node at its in-order position and depth, so you can watch where a new value lands. The layout is a pure function with its own test.
  • The graph tab shows the adjacency list and the search order separately, with the search controls on their own row.
  • 9 pytest tests, run on GitHub Actions on every push.

Brought up to date

  • The three structures are fully typed with Python’s newer generic syntax, for example class HashTable[K, V], and mypy checks them in strict mode.
  • uv fetches Python and the tools from one project file and a lock file, and Ruff lints and formats the code.
  • The tests, type check and lint run on Python 3.13, 3.14 and 3.15 on every push.

I made the 2026 review and fixes with Claude, an AI assistant, as a pair programmer. Each logic fix comes with a test.

The demo video on this page shows the 2023 version, before these fixes.


Run it

Needs uv, which fetches Python 3.13 or later with Tkinter included. The code itself uses only the standard library.

git clone https://github.com/mcneillium/DataStructuresAlgorithms.git
cd DataStructuresAlgorithms
uv run main_gui.py   # opens the app
uv run pytest        # runs the tests
uv run mypy          # checks the types

Tech stack

Python 3.13 to 3.15, Tkinter, pytest, mypy, Ruff, uv, GitHub Actions.