Skip to main content

Algorithms Library

A comprehensive, zero-dependency collection of common algorithms for Python. The package is designed to be production-ready, strongly typed, and easy to use.

Installation

pip install algorithms-lib

Quick Start

from algorithms_lib import quick_sort, merge_sort, binary_search, bfs, dijkstra

# Sorting
print(quick_sort([3, 1, 4, 1, 5, 9, 2, 6]))
# [1, 1, 2, 3, 4, 5, 6, 9]

# Searching
print(binary_search([1, 3, 5, 7, 9], 5))  # 2

# Graph traversal
graph = {'a': ['b', 'c'], 'b': ['d'], 'c': [], 'd': []}
print(bfs(graph, 'a'))  # ['a', 'b', 'c', 'd']

# Shortest path
weighted = {
    'a': [('b', 1), ('c', 4)],
    'b': [('c', 2), ('d', 5)],
    'c': [('d', 1)],
    'd': [],
}
distances, _ = dijkstra(weighted, 'a')
print(distances['d'])  # 4

Features

  • Zero runtime dependencies: No external packages required
  • Comprehensive coverage: Sorting, searching, graphs, dynamic programming, strings, greedy, and divide-and-conquer
  • Type safe: Includes py.typed marker for type checkers
  • Well tested: Full test coverage for normal use, edge cases, and invalid operations
  • Clear error messages: Explicit, helpful exceptions

Supported Algorithms

Sorting

  • quick_sort: in-place-memory quick sort
  • merge_sort: stable merge sort
  • heap_sort: binary max-heap sort
  • radix_sort: LSD radix sort for non-negative integers
  • tim_sort: Python's Timsort wrapper

Searching

  • binary_search: classic binary search
  • interpolation_search: interpolation search for numeric data
  • jump_search: jump search with block size sqrt(n)

Graphs

  • bfs: breadth-first search
  • dfs: iterative depth-first search
  • dijkstra: Dijkstra shortest paths (non-negative weights)
  • a_star: A* shortest path with heuristic
  • bellman_ford: shortest paths with negative-weight cycle detection

Dynamic Programming

  • knapsack_01: 0/1 knapsack maximum value
  • longest_common_subsequence: LCS length
  • edit_distance: Levenshtein distance

String Algorithms

  • kmp_search: Knuth-Morris-Pratt pattern matching
  • rabin_karp_search: rolling-hash pattern matching
  • boyer_moore_search: Boyer-Moore with bad-character rule

Greedy

  • activity_selection: maximum compatible activities
  • fractional_knapsack: fractional knapsack maximum value
  • huffman_coding: optimal prefix codes

Divide and Conquer

  • max_subarray: maximum subarray sum
  • count_inversions: inversion count via merge sort
  • fast_power: exponentiation by squaring

Development

pip install -e ".[dev]"
pytest test_algorithms_lib.py -v

License

MIT License. See LICENSE for details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

algorithms_lib-1.0.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

algorithms_lib-1.0.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file algorithms_lib-1.0.0.tar.gz.

File metadata

  • Download URL: algorithms_lib-1.0.0.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.5

File hashes

Hashes for algorithms_lib-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e768aef757b8ceabd41fd17e2b6e9f5723f1c940acba27d3d88b3275afea59a7
MD5 cca9767b1d509731adad9e333d96e393
BLAKE2b-256 081923bfd834c1dd256b580de888d72d0e8fca343bb7bb4c1f6dac3cf6c1202a

See more details on using hashes here.

File details

Details for the file algorithms_lib-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: algorithms_lib-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.5

File hashes

Hashes for algorithms_lib-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db0468af7a453c4e95cb04e3631a0154108750be17114f374010abdbdef674aa
MD5 46e36116b8f18a07bf6b6a4bd51961d1
BLAKE2b-256 02fff6ae79fbda5563ba7bbe1f89e3196366cd8d3e5e2b40e449e95b660ac203

See more details on using hashes here.

Release history Release notifications | RSS feed

2.0.0

2 files

This release

1.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page