A comprehensive and educational Python library of fundamental data structures, implemented with object-oriented programming principles and extensive documentation.
- Educational: Clear and well-documented code for learning
- Comprehensive: Exhaustive coverage of classic data structures
- Typed: Full MyPy support with strict type hints
- Tested: Complete test coverage with pytest
- Performant: Using
__slots__for memory optimization
The project is organized into thematic modules:
sds/
├── core/ # Fundamental components (abstract Node, interfaces, exceptions)
├── linear/ # Linear structures (lists, stacks, queues)
├── trees/ # Tree structures (binary trees, BST, AVL, heaps)
└── graphs/ # Graph structures (graphs, edges, algorithms)
All node types inherit from a common abstract Node class using a unified reference system (_refs).
SimpleNode: Node for singly linked lists (nextreference)DoublyNode: Node for doubly linked lists (nextandprevreferences)
BinaryNode: Node for binary trees (leftandrightreferences)TreeNode: Node for general trees (list ofchildren)
GraphNode: Node for graphs (unique identifier, no internal references)
LinkedList: Singly linked list- Complexity: O(1) prepend, O(n) append, O(n) index access
- Uses
SimpleNode
DoublyLinkedList: Doubly linked list- Complexity: O(1) prepend/append, O(n/2) optimized index access
- Uses
DoublyNode - Supports
__reversed__()for reverse iteration
CircularLinkedList: Circular linked listrotate()method for O(1) rotation- Last node points to first
Stack: LIFO (Last In First Out) stack- Operations:
push(),pop(),peek() - All operations in O(1)
- Uses
LinkedListinternally
- Operations:
Queue: FIFO (First In First Out) queue- Operations:
enqueue(),dequeue(),front(),rear() - Uses
LinkedListinternally
- Operations:
Deque: Double-ended queue- Operations:
add_front(),add_rear(),remove_front(),remove_rear() - All operations in O(1)
- Uses
DoublyLinkedListinternally
- Operations:
PriorityQueue: Priority queue- Element with minimum priority dequeued first
enqueue()in O(n),dequeue()in O(1)
BinaryTree: Simple binary tree- Traversals: inorder, preorder, postorder, level-order
- Operations: height, node count, search
BinarySearchTree(BST): Binary search tree- Property: left < parent < right
- Search, insertion, deletion
- O(log n) average, O(n) worst case
GeneralTree: General (n-ary) tree- Variable number of children per node
- DFS/BFS traversal
AVLTree: Self-balancing AVL tree- Guaranteed O(log n) for all operations
- Automatic rotations after insertion/deletion
RedBlackTree: Red-Black tree- Self-balancing with color properties
- Fewer rotations than AVL
MinHeap: Minimum heap- Parent ≤ children
- Extract-min in O(log n)
MaxHeap: Maximum heap- Parent ≥ children
- Extract-max in O(log n)
Trie: Prefix tree for strings- Auto-completion, prefix search
SegmentTree: Segment tree- Efficient range queries
BTree: B-tree for databases
GraphNode: Graph node with unique identifierEdge: Edge between two nodesDirectedEdge: Directed edgeWeightedEdge: Weighted edge
Graph: Basic graphDirectedGraph: Directed graphUndirectedGraph: Undirected graphWeightedGraph: Weighted graphWeightedDirectedGraph: a hybridation of Weighted and Directed graphAdjacencyListGraph: Graph with adjacency listAdjacencyMatrixGraph: Graph with adjacency 2D matrix
The project uses pytest with complete test coverage:
# Run all tests
pytest
# Run with coverage
pytest --cov=sds --cov-report=html
# Run tests for a specific module
pytest tests/02_linear/
# Run in verbose mode
pytest -vTest structure:
tests/
├── 01_Core/ # Tests for core (abstract Node, interfaces, exceptions)
├── 02_Linear/ # Tests for linear structures
├── 03_Tree/ # Tests for tree structures
└── 04_Graph/ # Tests for graph structures
The project is fully typed and verified with MyPy and Flake8:
# Type checking with MyPy (strict mode)
mypy --strict sds/
# Style checking with Flake8
flake8 sds/ --max-line-length=88
# Combined verification
mypy --strict sds/ && flake8 sds/ --max-line-length=88Contributions are welcome! Please follow these guidelines:
- Fork the project
- Create a branch for your feature (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- ✅ Type-checked code with MyPy (strict mode)
- ✅ Style compliant with Flake8 (PEP 8)
- ✅ Tests with pytest (coverage > 90%)
- ✅ NumPy format docstrings
- ✅ Use of
__slots__for memory optimization
- Modular architecture
- Abstract nodes with unified
_refssystem - Nodes for lists (SimpleNode, DoublyNode)
- Nodes for trees (BinaryNode, TreeNode)
- Nodes for graphs (GraphNode)
- Complete linear structures
- Exhaustive tests for linear
- Abstract interfaces (AbstractTree, AbstractBinaryTree)
- BinaryTree and BinarySearchTree
- B-Tree
- MinHeap and MaxHeap
- AVLTree
- RedBlackTree
- Trie
- Segment Tree
- Exhaustive tests for trees
- Edge, DirectedEdge, WeightedEdge
- Graph, DirectedGraph, UndirectedGraph
- Algorithms: DFS, BFS, Dijkstra, Kruskal
- Exhaustive tests for graphs
- Union-Find (Disjoint Set)
- Bloom Filter
- Skip List
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- Inspired by classic data structures courses
- Designed for learning and teaching
- Thanks to the Python community for exceptional tools (pytest, mypy, flake8, bandit)
Note: This project is under development. Features marked (coming soon) are planned but not yet implemented.