Skip to content

Commit 14ddb93

Browse files
committed
Handled type annotation and doctests
2 parents af534ad + a00d41c commit 14ddb93

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

graphs/johnson_graph.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ def __init__(self) -> None:
1414
self.graph: dict[str, list[tuple[str, int]]] = {}
1515

1616
# add vertices for a graph
17-
def add_vertices(self, u:int) -> None:
17+
def add_vertices(self, u: int) -> None:
1818
"""
1919
Adds a vertex `u` to the graph with an empty adjacency list.
2020
"""
2121
self.graph[u] = []
2222

2323
# assign weights for each edges formed of the directed graph
24-
def add_edge(self, u:str, v:str, w:int) -> None:
24+
def add_edge(self, u: str, v: str, w: int) -> None:
2525
"""
2626
Adds a directed edge from vertex `u` to vertex `v` with weight `w`.
2727
"""
2828
self.edges.append((u, v, w))
2929
self.graph[u].append((v, w))
3030

3131
# perform a dijkstra algorithm on a directed graph
32-
def dijkstra(self, s:str) -> dict:
32+
def dijkstra(self, s: str) -> dict:
3333
"""
3434
Computes the shortest path from vertex `s` to all other vertices using Dijkstra's algorithm.
3535
"""
@@ -49,7 +49,7 @@ def dijkstra(self, s:str) -> dict:
4949
return distances
5050

5151
# carry out the bellman ford algorithm for a node and estimate its distance vector
52-
def bellman_ford(self, s:str) -> dict:
52+
def bellman_ford(self, s: str) -> dict:
5353
"""
5454
Computes the shortest path from vertex `s` to all other vertices using the Bellman-Ford algorithm.
5555
"""

0 commit comments

Comments
 (0)