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.typedmarker 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 sortheap_sort: binary max-heap sortradix_sort: LSD radix sort for non-negative integersnative_sort: wrapper around the built-in sort
Searching
binary_search: classic binary searchinterpolation_search: interpolation search for numeric datajump_search: jump search with block sizesqrt(n)
Graphs
bfs: breadth-first searchdfs: iterative depth-first searchdijkstra: Dijkstra shortest paths (non-negative weights)a_star: A* shortest path with heuristicbellman_ford: shortest paths with negative-weight cycle detection
Dynamic Programming
knapsack_01: 0/1 knapsack maximum valuelongest_common_subsequence: LCS lengthedit_distance: Levenshtein distance
String Algorithms
kmp_search: Knuth-Morris-Pratt pattern matchingrabin_karp_search: rolling-hash pattern matchingboyer_moore_search: Boyer-Moore with bad-character and good-suffix rules; reports overlapping matches
Greedy
activity_selection: maximum compatible activitiesfractional_knapsack: fractional knapsack maximum valuehuffman_coding: optimal prefix codes
Divide and Conquer
max_subarray: maximum subarray sumcount_inversions: inversion count via merge sortfast_power: exponentiation by squaring
Development
pip install -e ".[dev]"
pytest test_algorithms_lib.py -v
License
MIT License. See LICENSE for details.
Metadata
Release files for algorithms-lib 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| algorithms_lib-2.0.0.tar.gz | 18.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| algorithms_lib-2.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 39.0 kB
Release files / algorithms_lib-2.0.0.tar.gz
| Download URL | algorithms_lib-2.0.0.tar.gz |
|---|---|
| Size | 18.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7d9e90330506285342b3556bd002ba77c51743c155c71f8a3dd5a1af829abd8
|
|
BLAKE2b-256 checksum How to use checksums |
8823a41bb45d69f1fd977b1d4b0ad2752c6e202159486ee2b0b021f619f53f60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / algorithms_lib-2.0.0-py3-none-any.whl
| Download URL | algorithms_lib-2.0.0-py3-none-any.whl |
|---|---|
| Size | 20.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
46da0c3a5c2e72b110c18191275b68e3115e9fcfe63326b8c36f3ccdfd536b8d
|
|
BLAKE2b-256 checksum How to use checksums |
ecbf3b920fe7b08a3dccd798a8ce2f07ae62b9cabf74a75829f7efc679df390e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for algorithms-lib 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.