Skip to content

Commit ab95b7b

Browse files
committed
Add/fix mypy type annotations at BFS, DFS in graphs
1 parent f37d415 commit ab95b7b

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

graphs/breadth_first_search.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
""" Author: OMKAR PATHAK """
44

5-
from typing import Set
5+
from typing import Dict, List, Set
66

77

88
class Graph:
99
def __init__(self) -> None:
10-
self.vertices = {}
10+
self.vertices: Dict[int, List[int]] = {}
1111

1212
def print_graph(self) -> None:
1313
"""

graphs/depth_first_search.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
from __future__ import annotations
44

5+
from typing import Set
56

6-
def depth_first_search(graph: dict, start: str) -> set[int]:
7+
8+
def depth_first_search(graph: dict, start: str) -> Set[str]:
79
"""Depth First Search on Graph
810
:param graph: directed graph in dictionary format
9-
:param vertex: starting vertex as a string
11+
:param start: starting vertex as a string
1012
:returns: the trace of the search
11-
>>> G = { "A": ["B", "C", "D"], "B": ["A", "D", "E"],
13+
>>> input_G = { "A": ["B", "C", "D"], "B": ["A", "D", "E"],
1214
... "C": ["A", "F"], "D": ["B", "D"], "E": ["B", "F"],
1315
... "F": ["C", "E", "G"], "G": ["F"] }
14-
>>> start = "A"
1516
>>> output_G = list({'A', 'B', 'C', 'D', 'E', 'F', 'G'})
16-
>>> all(x in output_G for x in list(depth_first_search(G, "A")))
17+
>>> all(x in output_G for x in list(depth_first_search(input_G, "A")))
1718
True
18-
>>> all(x in output_G for x in list(depth_first_search(G, "G")))
19+
>>> all(x in output_G for x in list(depth_first_search(input_G, "G")))
1920
True
2021
"""
2122
explored, stack = set(start), [start]

scripts/build_directory_md.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55

66
URL_BASE = "https://github.com/TheAlgorithms/Python/blob/master"
77

8+
IGNORED_DIRS = ["scripts", "venv"]
9+
810

911
def good_file_paths(top_dir: str = ".") -> Iterator[str]:
1012
for dir_path, dir_names, filenames in os.walk(top_dir):
11-
dir_names[:] = [d for d in dir_names if d != "scripts" and d[0] not in "._"]
13+
dir_names[:] = [
14+
d for d in dir_names if d not in IGNORED_DIRS and d[0] not in "._"
15+
]
1216
for filename in filenames:
1317
if filename == "__init__.py":
1418
continue

0 commit comments

Comments
 (0)