A curated collection of classic algorithms and data structures implemented in Python — for learning and reference.
This repository contains topic‑organized Python implementations ranging from searching, sorting, backtracking, dynamic programming, graph theory, linear algebra, machine learning, image processing, and more. Implementations prioritize clarity and education over micro‑optimizations.
Important notes:
- These implementations are educational. Prefer the Python standard library or well‑maintained third‑party libraries for production.
- Many modules include doctests and/or runnable examples.
- Python >= 3.14
- Optional tooling: uv for fast dependency management, pytest for tests, ruff for lint/format, Sphinx for docs.
You can use this repository without installing anything (run modules directly), or set up a virtual environment and install dependencies.
Recommended with uv (uses pyproject.toml and uv.lock):
# Create a virtual environment and install base dependencies
uv sync
# Optionally install additional groups
uv sync -g test # test tools
uv sync -g docs # documentation build toolsAlternative with pip (base dependencies only):
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -e .Run an algorithm module directly (prints results to the console):
python -m backtracking.n_queensImport and use a function in your own code:
from bit_manipulation.is_power_of_two import is_power_of_two
print(is_power_of_two(8)) # True
print(is_power_of_two(17)) # FalseMost modules contain doctest examples. You can run them via pytest or directly from the module when available.
Top‑level topic folders (non‑exhaustive):
backtracking/— N‑Queens, Sudoku, Hamiltonian cycle, and related search problemsbit_manipulation/— bitwise operations, Gray code, counting bits, power‑of‑two checksdata_structures/— stacks, queues, hash maps, trees, heapsdivide_and_conquer/,dynamic_programming/,greedy_methods/— core algorithmic paradigmsgraphs/,networking_flow/— graph traversal, shortest paths, max flowmaths/,linear_algebra/,matrix/— numerical and algebraic utilitiessorts/,searches/— classic sorting and searching algorithmscomputer_vision/,digital_image_processing/,audio_filters/— signal and image processingmachine_learning/,neural_network/— basic ML and NN examplesproject_euler/— Project Euler problem solutions (not covered by test coverage)
Explore each folder’s README.md where present for more details.
This project uses pytest and doctests.
uv run pytest -q # with uv
# or
pytest -q # if installed in your environmentThis repository is configured for ruff (format + lint). Suggested workflow:
uv run ruff format .
uv run ruff check .The configuration lives in pyproject.toml and targets Python 3.14.
Sphinx configuration is provided. To build HTML docs locally:
uv sync -g docs
uv run sphinx-build -b html docs docs/_build/htmlOpen docs/_build/html/index.html in a browser.
Contributions are welcome. Keep implementations simple, readable, and well‑documented. Prefer type hints and include doctests where practical. Please run ruff and tests before opening a PR.
MIT — see LICENSE.md.
This codebase is inspired by and derived from the open‑source efforts of the TheAlgorithms community. Thanks to all contributors for educational implementations and ideas.