1 parent 367f8ce commit 728c0dfCopy full SHA for 728c0df
1 file changed
graphs/breadth_first_search_shortest_path.py
@@ -16,7 +16,7 @@
16
17
class Graph:
18
def __init__(self, graph: Dict[str, str], source_vertex: str) -> None:
19
- """Graph is implemented as dictionary of adjancency lists. Also,
+ """Graph is implemented as dictionary of adjacency lists. Also,
20
Source vertex have to be defined upon initialization.
21
"""
22
self.graph = graph
@@ -37,11 +37,11 @@ def breath_first_search(self) -> None:
37
38
while queue:
39
vertex = queue.pop(0)
40
- for adjancent_vertex in self.graph[vertex]:
41
- if adjancent_vertex not in visited:
42
- visited.add(adjancent_vertex)
43
- self.parent[adjancent_vertex] = vertex
44
- queue.append(adjancent_vertex)
+ for adjacent_vertex in self.graph[vertex]:
+ if adjacent_vertex not in visited:
+ visited.add(adjacent_vertex)
+ self.parent[adjacent_vertex] = vertex
+ queue.append(adjacent_vertex)
45
46
def shortest_path(self, target_vertex: str) -> str:
47
"""This shortest path function returns a string, describing the result:
0 commit comments