Skip to content

Commit b895e6c

Browse files
authored
Merge branch 'TheAlgorithms:master' into master
2 parents 8467b86 + 841e947 commit b895e6c

32 files changed

+987
-73
lines changed

.github/workflows/sphinx.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
python-version: 3.14
4040
allow-prereleases: true
4141
- run: uv sync --group=docs
42-
- uses: actions/configure-pages@v5
42+
- uses: actions/configure-pages@v6
4343
- run: uv run sphinx-build -c docs . docs/_build/html
4444
- uses: actions/upload-pages-artifact@v4
4545
with:
@@ -53,5 +53,5 @@ jobs:
5353
needs: build_docs
5454
runs-on: ubuntu-latest
5555
steps:
56-
- uses: actions/deploy-pages@v4
56+
- uses: actions/deploy-pages@v5
5757
id: deployment

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ repos:
1414
- id: requirements-txt-fixer
1515

1616
- repo: https://github.com/MarcoGorelli/auto-walrus
17-
rev: 0.3.4
17+
rev: 0.4.1
1818
hooks:
1919
- id: auto-walrus
2020

2121
- repo: https://github.com/astral-sh/ruff-pre-commit
22-
rev: v0.14.10
22+
rev: v0.14.14
2323
hooks:
2424
- id: ruff-check
2525
- id: ruff-format
@@ -32,7 +32,7 @@ repos:
3232
- tomli
3333

3434
- repo: https://github.com/tox-dev/pyproject-fmt
35-
rev: v2.11.1
35+
rev: v2.12.1
3636
hooks:
3737
- id: pyproject-fmt
3838

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ We want your work to be readable by others; therefore, we encourage you to note
159159
starting_value = int(input("Please enter a starting value: ").strip())
160160
```
161161

162-
The use of [Python type hints](https://docs.python.org/3/library/typing.html) is encouraged for function parameters and return values. Our automated testing will run [mypy](http://mypy-lang.org) so run that locally before making your submission.
162+
The use of [Python type hints](https://docs.python.org/3/library/typing.html) is encouraged for function parameters and return values. Our automated testing will run [mypy](https://mypy-lang.org) so run that locally before making your submission.
163163

164164
```python
165165
def sum_ab(a: int, b: int) -> int:

DIRECTORY.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,11 @@
469469

470470
## Geometry
471471
* [Geometry](geometry/geometry.py)
472+
* [Graham Scan](geometry/graham_scan.py)
473+
* [Jarvis March](geometry/jarvis_march.py)
474+
* Tests
475+
* [Test Graham Scan](geometry/tests/test_graham_scan.py)
476+
* [Test Jarvis March](geometry/tests/test_jarvis_march.py)
472477

473478
## Graphics
474479
* [Bezier Curve](graphics/bezier_curve.py)
@@ -881,6 +886,7 @@
881886
* [Quine](other/quine.py)
882887
* [Scoring Algorithm](other/scoring_algorithm.py)
883888
* [Sdes](other/sdes.py)
889+
* [Sliding Window Maximum](other/sliding_window_maximum.py)
884890
* [Tower Of Hanoi](other/tower_of_hanoi.py)
885891
* [Word Search](other/word_search.py)
886892

@@ -980,6 +986,7 @@
980986
* [Sol2](project_euler/problem_014/sol2.py)
981987
* Problem 015
982988
* [Sol1](project_euler/problem_015/sol1.py)
989+
* [Sol2](project_euler/problem_015/sol2.py)
983990
* Problem 016
984991
* [Sol1](project_euler/problem_016/sol1.py)
985992
* [Sol2](project_euler/problem_016/sol2.py)

backtracking/coloring.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ def color(graph: list[list[int]], max_colors: int) -> list[int]:
104104
>>> max_colors = 2
105105
>>> color(graph, max_colors)
106106
[]
107+
>>> color([], 2) # empty graph
108+
[]
109+
>>> color([[0]], 1) # single node, 1 color
110+
[0]
111+
>>> color([[0, 1], [1, 0]], 1) # 2 nodes, 1 color (impossible)
112+
[]
113+
>>> color([[0, 1], [1, 0]], 2) # 2 nodes, 2 colors (possible)
114+
[0, 1]
107115
"""
108116
colored_vertices = [-1] * len(graph)
109117

backtracking/generate_parentheses.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ def generate_parenthesis(n: int) -> list[str]:
6464
Example 2:
6565
>>> generate_parenthesis(1)
6666
['()']
67+
68+
Example 3:
69+
>>> generate_parenthesis(0)
70+
['']
6771
"""
6872

6973
result: list[str] = []

backtracking/generate_parentheses_iterative.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
def generate_parentheses_iterative(length: int) -> list:
1+
def generate_parentheses_iterative(length: int) -> list[str]:
22
"""
33
Generate all valid combinations of parentheses (Iterative Approach).
44
55
The algorithm works as follows:
66
1. Initialize an empty list to store the combinations.
77
2. Initialize a stack to keep track of partial combinations.
8-
3. Start with empty string and push it onstack along with the counts of '(' and ')'.
8+
3. Start with empty string and push it on stack along with
9+
the counts of '(' and ')'.
910
4. While the stack is not empty:
1011
a. Pop a partial combination and its open and close counts from the stack.
1112
b. If the combination length is equal to 2*length, add it to the result.
@@ -34,8 +35,11 @@ def generate_parentheses_iterative(length: int) -> list:
3435
>>> generate_parentheses_iterative(0)
3536
['']
3637
"""
37-
result = []
38-
stack = []
38+
if length == 0:
39+
return [""]
40+
41+
result: list[str] = []
42+
stack: list[tuple[str, int, int]] = []
3943

4044
# Each element in stack is a tuple (current_combination, open_count, close_count)
4145
stack.append(("", 0, 0))
@@ -45,6 +49,7 @@ def generate_parentheses_iterative(length: int) -> list:
4549

4650
if len(current_combination) == 2 * length:
4751
result.append(current_combination)
52+
continue
4853

4954
if open_count < length:
5055
stack.append((current_combination + "(", open_count + 1, close_count))

backtracking/n_queens.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ def is_safe(board: list[list[int]], row: int, column: int) -> bool:
3333
False
3434
>>> is_safe([[0, 0, 1], [0, 0, 0], [0, 0, 0]], 1, 1)
3535
False
36+
>>> is_safe([[1, 0, 0], [0, 0, 0], [0, 0, 0]], 1, 2)
37+
True
38+
>>> is_safe([[1, 0, 0], [0, 0, 0], [0, 0, 0]], 2, 1)
39+
True
40+
>>> is_safe([[0, 0, 0], [1, 0, 0], [0, 0, 0]], 0, 2)
41+
True
42+
>>> is_safe([[0, 0, 0], [1, 0, 0], [0, 0, 0]], 2, 2)
43+
True
3644
"""
3745

3846
n = len(board) # Size of the board

backtracking/word_break.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def word_break(input_string: str, word_dict: set[str]) -> bool:
6666
6767
>>> word_break("catsandog", {"cats", "dog", "sand", "and", "cat"})
6868
False
69+
70+
>>> word_break("applepenapple", {})
71+
False
6972
"""
7073

7174
return backtrack(input_string, word_dict, 0)

data_structures/hashing/hash_table_with_linked_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def __init__(self, *args, **kwargs):
88
super().__init__(*args, **kwargs)
99

1010
def _set_value(self, key, data):
11-
self.values[key] = deque([]) if self.values[key] is None else self.values[key]
11+
self.values[key] = deque() if self.values[key] is None else self.values[key]
1212
self.values[key].appendleft(data)
1313
self._keys[key] = self.values[key]
1414

0 commit comments

Comments
 (0)