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: in-place-memory quick sortmerge_sort: stable merge sortheap_sort: binary max-heap sortradix_sort: LSD radix sort for non-negative integerstim_sort: Python's Timsort wrapper
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 rule
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-1.0.0.tar.gz
(12.4 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-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e768aef757b8ceabd41fd17e2b6e9f5723f1c940acba27d3d88b3275afea59a7
|
|
| MD5 |
cca9767b1d509731adad9e333d96e393
|
|
| BLAKE2b-256 |
081923bfd834c1dd256b580de888d72d0e8fca343bb7bb4c1f6dac3cf6c1202a
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db0468af7a453c4e95cb04e3631a0154108750be17114f374010abdbdef674aa
|
|
| MD5 |
46e36116b8f18a07bf6b6a4bd51961d1
|
|
| BLAKE2b-256 |
02fff6ae79fbda5563ba7bbe1f89e3196366cd8d3e5e2b40e449e95b660ac203
|