Data structures implemented from scratch for learning and experimentation.
Project description
py-ds-academy
A small playground project for implementing classic data structures from scratch in Python.
The goal is learning + correctness (with tests), not squeezing out every last micro-optimization.
๐งฑ Project Goals
- Implement core data structures from scratch in Python
- Use type hints, clean APIs, and unit tests
- Compare different implementations (e.g., list-backed vs linked)
- Practice algorithmic reasoning & complexity analysis
๐ฆ Project Layout
py-ds-academy/
โโ pyproject.toml
โโ README.md
โโ .python-version
โโ src/
โ โโโ py_ds/
โ โโโ __init__.py
โ โโโ datastructures/
โ โโโ __init__.py
โ โโโ stack.py
โ โโโ queue.py
โ โโโ heaps.py
โ โโโ linked_lists/
โ โ โโโ __init__.py
โ โ โโโ base.py
โ โ โโโ singly_linked.py
โ โ โโโ doubly_linked.py
โ โโโ trees/
โ โโโ __init__.py
โ โโโ base.py
โ โโโ binary_search_tree.py
โ โโโ avl.py
โโ tests/
โโ test_stack.py
โโ test_queue.py
โโ test_linked_list.py
โโ test_doubly_linked_list.py
โโ test_max_heap.py
โโ test_min_heap.py
โโ test_binary_search_tree.py
โโ test_avl_tree.py
All importable code lives under src/py_ds/.
๐ Getting Started
Requires uv.
# create venv from .python-version
uv venv
# install dependencies (if any)
uv sync
# run tests
uv run pytest
You can also drop into a REPL:
uv run python
>>> from py_ds import Stack, Queue, SinglyLinkedList, DoublyLinkedList
>>> from py_ds import MinHeap, MaxHeap, BinarySearchTree, AVLTree
>>> # Stack example
>>> s = Stack([1, 2, 3])
>>> s.pop()
3
>>> # Queue example
>>> q = Queue([1, 2, 3])
>>> q.dequeue()
1
>>> # Linked List example
>>> ll = SinglyLinkedList([1, 2, 3])
>>> ll.append(4)
>>> list(ll)
[1, 2, 3, 4]
>>> # Heap example
>>> h = MinHeap([3, 1, 4, 1, 5])
>>> h.pop()
1
>>> # BST example
>>> bst = BinarySearchTree([5, 3, 7, 2, 4])
>>> list(bst.inorder())
[2, 3, 4, 5, 7]
๐ Data Structures Roadmap
1. Linear Structures
Stacks โ
-
Stackbacked by Python list - Operations:
push,pop,peek,is_empty,__len__,clear,extend,to_list - Iteration support (
__iter__)
Queues โ
-
Queuebacked by Python list - Operations:
enqueue,dequeue,peek,is_empty,__len__,clear,extend,to_list - Iteration support (
__iter__)
Linked Lists โ
-
SinglyLinkedList-
append,prepend,insert,remove,pop,find - Iteration support (
__iter__) - Indexing support (
__getitem__,__setitem__) -
head(),tail(),clear()
-
-
DoublyLinkedList- Efficient O(1)
appendandprepend(with tail pointer) - Bidirectional traversal (
__iter__,reverse_iter) - All operations from
SinglyLinkedList - Optimized indexing with bidirectional search
- Efficient O(1)
2. Trees
Binary Tree (generic node-based) โ
-
BinaryTreebase class with_BinaryNode - Traversals:
- Preorder (
preorder()) - Inorder (
inorder()) - Postorder (
postorder()) - Level-order / BFS (
level_order())
- Preorder (
- Tree height calculation
- Tree visualization (
__str__)
Binary Search Tree (BST) โ
-
BinarySearchTreeimplementation - Insert
- Search (
__contains__) - Delete (
remove) - handles 0, 1, 2 children - Find min / max (
min(),max()) - Inherits all traversals from
BinaryTree
Self-Balancing Trees โ
-
AVLTree- self-balancing BST- Automatic rebalancing on insert/remove
- Rotations: left, right, left-right, right-left
- Balance factor calculation
- Inherits all BST operations
3. Heaps / Priority Queues โ
Binary Heap
-
Heapabstract base class -
MinHeapimplementation -
MaxHeapimplementation - Operations:
push,pop,peek - Heap construction from iterable
-
heapify_upandheapify_downoperations - Use cases: priority queue, heap sort
4. Hash-Based Structures
Hash Map
- Array of buckets
- Collision handling via chaining (linked lists) or open addressing
- Operations:
get,set,delete,__contains__ - Basic resizing & load factor
Hash Set
- Built on top of
HashMap - Operations:
add,remove,contains, iteration
5. Graphs
Graph Representations
- Adjacency list representation
- Optional: adjacency matrix
Algorithms
- BFS (breadth-first search)
- DFS (depth-first search)
- Path search (e.g.
has_path(u, v))
Stretch:
- Topological sort
- Dijkstraโs algorithm (weighted graphs)
โจ Implemented Features Summary
The following data structures are fully implemented and tested:
- โ Stack - LIFO stack with list backing
- โ Queue - FIFO queue with list backing
- โ SinglyLinkedList - Single-direction linked list
- โ DoublyLinkedList - Double-direction linked list with O(1) append/prepend
- โ MinHeap - Minimum binary heap
- โ MaxHeap - Maximum binary heap
- โ BinarySearchTree - Binary search tree with insert, remove, search, min/max
- โ AVLTree - Self-balancing AVL tree (extends BST)
๐งช Testing
Each data structure gets its own test module under tests/.
Run the whole suite:
uv run pytest
๐ง Design Principles
- Prefer clear, readable code over cleverness
- Use type hints everywhere
- Raise the right built-in exceptions
- Document time complexity in docstrings
This project is mainly for learning + fun. No guarantees โ just data structures implemented by hand.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_ds_academy-0.5.7.tar.gz.
File metadata
- Download URL: py_ds_academy-0.5.7.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
884ba81b49e5364fd8005b83ee92095106161606ca7bcd08f1e0f1c9b2e8395c
|
|
| MD5 |
78d78a763abe648f9e50358b23a30674
|
|
| BLAKE2b-256 |
162df9c32902eac2a5e9234a90d7d3cd90650e9baf107d72d51a4a29367c6028
|
File details
Details for the file py_ds_academy-0.5.7-py3-none-any.whl.
File metadata
- Download URL: py_ds_academy-0.5.7-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53fd67a07b0786fe06069652df0fbc1e725de4bfda3b6e6e8828fbee86eb8572
|
|
| MD5 |
5a97744ae7b8f9327477533b378b9b01
|
|
| BLAKE2b-256 |
09b84e6e4e356b06b99d02cc181cb5e64399928d6f4e0f2f70f7726922fbf03a
|