Skip to content

Commit dc96be7

Browse files
committed
Fix
1 parent 3c2ccb9 commit dc96be7

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

dynamic_programming/knapsack.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def _construct_solution(dp: list, wt: list, i: int, j: int, optimal_set: set):
108108
Parameters
109109
----------
110110
111-
* `dp`: list of list, the table of a solved integer weight dynamic programming problem
111+
* `dp`: list of list, the table of a solved integer weight dynamic programming
112+
problem
112113
* `wt`: list or tuple, the vector of weights of the items
113114
* `i`: int, the index of the item under consideration
114115
* `j`: int, the current possible maximum weight

dynamic_programming/matrix_chain_multiplication.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
1818
python -m doctest -v matrix_chain_multiply.py
1919
20-
Given a sequence ``arr[]`` that represents chain of 2D matrices such that the dimension of
21-
the ``i`` th matrix is ``arr[i-1]*arr[i]``.
20+
Given a sequence ``arr[]`` that represents chain of 2D matrices such that the dimension
21+
of the ``i`` th matrix is ``arr[i-1]*arr[i]``.
2222
So suppose ``arr = [40, 20, 30, 10, 30]`` means we have ``4`` matrices of dimensions
2323
``40*20``, ``20*30``, ``30*10`` and ``10*30``.
2424
25-
``matrix_chain_multiply()`` returns an integer denoting minimum number of multiplications to
26-
multiply the chain.
25+
``matrix_chain_multiply()`` returns an integer denoting minimum number of
26+
multiplications to multiply the chain.
2727
2828
We do not need to perform actual multiplication here.
2929
We only need to decide the order in which to perform the multiplication.
@@ -32,7 +32,8 @@
3232
1. Number of multiplications (ie cost) to multiply ``2`` matrices
3333
of size ``m*p`` and ``p*n`` is ``m*p*n``.
3434
2. Cost of matrix multiplication is not associative ie ``(M1*M2)*M3 != M1*(M2*M3)``
35-
3. Matrix multiplication is not commutative. So, ``M1*M2`` does not mean ``M2*M1`` can be done.
35+
3. Matrix multiplication is not commutative. So, ``M1*M2`` does not mean ``M2*M1``
36+
can be done.
3637
4. To determine the required order, we can try different combinations.
3738
3839
So, this problem has overlapping sub-problems and can be solved using recursion.

dynamic_programming/regex_match.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
def recursive_match(text: str, pattern: str) -> bool:
14-
"""
14+
r"""
1515
Recursive matching algorithm.
1616
1717
| Time complexity: O(2^(\|text\| + \|pattern\|))
@@ -50,7 +50,7 @@ def recursive_match(text: str, pattern: str) -> bool:
5050

5151

5252
def dp_match(text: str, pattern: str) -> bool:
53-
"""
53+
r"""
5454
Dynamic programming matching algorithm.
5555
5656
| Time complexity: O(\|text\| * \|pattern\|)

dynamic_programming/rod_cutting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def top_down_cut_rod(n: int, prices: list):
6969
price for a rod of length ``i``
7070
7171
.. note::
72-
For convenience and because Python's lists using ``0``-indexing, ``length(max_rev) =
73-
n + 1``, to accommodate for the revenue obtainable from a rod of length ``0```.
72+
For convenience and because Python's lists using ``0``-indexing, ``length(max_rev)
73+
= n + 1``, to accommodate for the revenue obtainable from a rod of length ``0``.
7474
7575
Returns
7676
-------

0 commit comments

Comments
 (0)