Skip to content

Commit a93cd95

Browse files
authored
Merge branch 'TheAlgorithms:master' into master
2 parents fed9f83 + 5f61af4 commit a93cd95

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

data_structures/heap/heap.py

+31-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,37 @@ def __repr__(self) -> str:
5353
return str(self.h)
5454

5555
def parent_index(self, child_idx: int) -> int | None:
56-
"""return the parent index of given child"""
56+
"""
57+
returns the parent index based on the given child index
58+
59+
>>> h = Heap()
60+
>>> h.build_max_heap([103, 9, 1, 7, 11, 15, 25, 201, 209, 107, 5])
61+
>>> h
62+
[209, 201, 25, 103, 107, 15, 1, 9, 7, 11, 5]
63+
64+
>>> h.parent_index(-1) # returns none if index is <=0
65+
66+
>>> h.parent_index(0) # returns none if index is <=0
67+
68+
>>> h.parent_index(1)
69+
0
70+
>>> h.parent_index(2)
71+
0
72+
>>> h.parent_index(3)
73+
1
74+
>>> h.parent_index(4)
75+
1
76+
>>> h.parent_index(5)
77+
2
78+
>>> h.parent_index(10.5)
79+
4.0
80+
>>> h.parent_index(209.0)
81+
104.0
82+
>>> h.parent_index("Test")
83+
Traceback (most recent call last):
84+
...
85+
TypeError: '>' not supported between instances of 'str' and 'int'
86+
"""
5787
if child_idx > 0:
5888
return (child_idx - 1) // 2
5989
return None

scripts/build_directory_md.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
def good_file_paths(top_dir: str = ".") -> Iterator[str]:
88
for dir_path, dir_names, filenames in os.walk(top_dir):
9-
dir_names[:] = [d for d in dir_names if d != "scripts" and d[0] not in "._"]
9+
dir_names[:] = [
10+
d
11+
for d in dir_names
12+
if d != "scripts" and d[0] not in "._" and "venv" not in d
13+
]
1014
for filename in filenames:
1115
if filename == "__init__.py":
1216
continue

0 commit comments

Comments
 (0)