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.
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)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7d9e90330506285342b3556bd002ba77c51743c155c71f8a3dd5a1af829abd8
|
|
| MD5 |
7a5c6709179768ad165bf1d99fc6e61c
|
|
| BLAKE2b-256 |
8823a41bb45d69f1fd977b1d4b0ad2752c6e202159486ee2b0b021f619f53f60
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46da0c3a5c2e72b110c18191275b68e3115e9fcfe63326b8c36f3ccdfd536b8d
|
|
| MD5 |
c79c0c2eebfa3da9894e116358a93124
|
|
| BLAKE2b-256 |
ecbf3b920fe7b08a3dccd798a8ce2f07ae62b9cabf74a75829f7efc679df390e
|