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: quick sort (returns a new list, not in-place)
  • merge_sort: stable merge sort
  • heap_sort: binary max-heap sort
  • radix_sort: LSD radix sort for non-negative integers
  • native_sort: wrapper around the built-in sort

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 and good-suffix rules; reports overlapping matches

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-2.0.0.tar.gz (18.9 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-2.0.0-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for algorithms_lib-2.0.0.tar.gz
Algorithm Hash digest
SHA256 b7d9e90330506285342b3556bd002ba77c51743c155c71f8a3dd5a1af829abd8
MD5 7a5c6709179768ad165bf1d99fc6e61c
BLAKE2b-256 8823a41bb45d69f1fd977b1d4b0ad2752c6e202159486ee2b0b021f619f53f60

See more details on using hashes here.

File details

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

File metadata

  • Download URL: algorithms_lib-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 20.1 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-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 46da0c3a5c2e72b110c18191275b68e3115e9fcfe63326b8c36f3ccdfd536b8d
MD5 c79c0c2eebfa3da9894e116358a93124
BLAKE2b-256 ecbf3b920fe7b08a3dccd798a8ce2f07ae62b9cabf74a75829f7efc679df390e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 files

1.0.0

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