Library for Studying Dynamic Programming
DP is suitable for a particular kind of problem (computation) structure: the subproblems are highly overlapping (usually with exponential time complexity, like 2^n) and the recurrence relation can be clearly defined.
In this library, I provide implementations of two major DP approaches – (1) top-down (recursion + memoization); (2) bottom-up (tabulation) – for some well-known DP problems, including:
Fibonacci_Numbers
House_Robber
Min_Cost_Climbing_Stairs
Maximum_Subarray
Best_Time_to_Buy_and_Sell_Stock
Coin_Change
Word_Break
Decode_Ways
Installation
pip install dynamic-programming
Sample Usage
>>> from DP import Fibonacci_Numbers as fib >>> F = fib() >>> F.explanation() # this will show the code and some explanations >>> F.top_down(n = 10) 55 >>> F.bottom_up(n = 10) 55
>>> from DP import House_Robber as robber >>> r = robber() >>> r.explanation() # this will show the code and some explanations >>> r.top_down(nums = [3, 10, 3, 1, 2, 4, 10, 2, 44, 98]) 120 >>> r.bottom_up(nums = [3, 10, 3, 1, 2, 4, 10, 2, 44, 98]) 120
>>> from DP import Min_Cost_Climbing_Stairs as climb >>> c = climb() >>> c.explanation() # this will show the code and some explanations >>> c.top_down(cost = [3, 10, 3, 1, 2, 4, 10, 2, 44, 98]) 57 >>> c.bottom_up(cost = [3, 10, 3, 1, 2, 4, 10, 2, 44, 98]) 57
>>> from DP import Maximum_Subarray as maxsub >>> m = maxsub() >>> m.explanation() # this will show the code and some explanations >>> m.top_down(nums=[-2, 1, -3, 4, -1, 2, 1, -5, 4, 9, -2, 10, 15, -3, -4]) [4, -1, 2, 1, -5, 4, 9, -2, 10, 15] has the largest sum = 37. >>> m.bottom_up(nums=[-2, 1, -3, 4, -1, 2, 1, -5, 4, 9, -2, 10, 15, -3, -4]) [4, -1, 2, 1, -5, 4, 9, -2, 10, 15] has the largest sum = 37.
>>> from DP import Best_Time_to_Buy_and_Sell_Stock as stock >>> s = stock() >>> s.explanation() # this will show the code and some explanations >>> s.top_down(prices=[7, 1, 5, 3, 6, 4, 2, 10, 2, 3, 9, 1]) 9 >>> s.bottom_up(prices=[7, 1, 5, 3, 6, 4, 2, 10, 2, 3, 9, 1]) 9
>>> from DP import Coin_Change as coin >>> c = coin() >>> c.explanation() # this will show the code and some explanations >>> c.top_down(coins=[1, 5, 10, 25], amount=150) 6 >>> c.bottom_up(coins=[1, 5, 10, 25], amount=150) 6
>>> from DP import Word_Break as wordbreak >>> w = wordbreak() >>> w.explanation() # this will show the code and some explanations >>> w.top_down(s = "codingisfunpythonisgreat", wordDict = ["coding", "is", "fun", "python", "great"]) True >>> w.bottom_up(s = "codingisfunpythonisgreat", wordDict = ["coding", "is", "fun", "python", "great"]) True
>>> from DP import Decode_Ways as decode >>> d = decode() >>> d.explanation() # this will show the code and some explanations >>> d.top_down(s = "12812823") 8 >>> d.bottom_up(s = "12812823") 8
Metadata
Release files for dynamic-programming 0.0.2
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 | Actions |
|---|---|---|---|---|
| dynamic-programming-0.0.2.tar.gz | 17.9 kB | Without provenance | Details for dynamic-programming-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dynamic_programming-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for dynamic_programming-0.0.2-py3-none-any.whl |
Total release size: 46.0 kB
Release files / dynamic-programming-0.0.2.tar.gz
| Download URL | dynamic-programming-0.0.2.tar.gz |
|---|---|
| Size | 17.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9fc9d43538cd8fdbfe41f316a3257eb191683f8daa8f5d962ed9e15d325ef052
|
|
BLAKE2b-256 checksum How to use checksums |
6c9680d4820f75f769c5ddf653ae1e931adc4c240b69a6cecf3670fbed2e997a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.3
|
Release files / dynamic_programming-0.0.2-py3-none-any.whl
| Download URL | dynamic_programming-0.0.2-py3-none-any.whl |
|---|---|
| Size | 28.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
342d3da153140caabf3f7eab8fa9108686bfaa49060e8cee43aa154980a71130
|
|
BLAKE2b-256 checksum How to use checksums |
8eefe4bf750d811b9cf1d29e4c41b0ba2793c92128f7e7bcaf2f4bf25c79969c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.3
|
Security for dynamic-programming 0.0.2
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.