Skip to content

Commit 9a4e1d3

Browse files
committed
Handled type annotation
1 parent 1fca8c6 commit 9a4e1d3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

graphs/johnson_graph.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
class JohnsonGraph:
99
def __init__(self) -> None:
1010
self.edges: list[str] = []
11-
self.graph: dict[str, int] = {}
11+
self.graph: dict[str, list] = {}
1212

1313
# add vertices for a graph
14-
def add_vertices(self, u) -> None:
14+
def add_vertices(self, u:int) -> None:
1515
self.graph[u] = []
1616

1717
# assign weights for each edges formed of the directed graph
18-
def add_edge(self, u, v, w) -> None:
18+
def add_edge(self, u:str, v:str, w:int) -> None:
1919
self.edges.append((u, v, w))
2020
self.graph[u].append((v, w))
2121

2222
# perform a dijkstra algorithm on a directed graph
23-
def dijkstra(self, s) -> dict:
23+
def dijkstra(self, s:str) -> dict:
2424
distances = {vertex: sys.maxsize - 1 for vertex in self.graph}
2525
pq = [(0, s)]
2626
distances[s] = 0
@@ -37,7 +37,7 @@ def dijkstra(self, s) -> dict:
3737
return distances
3838

3939
# carry out the bellman ford algorithm for a node and estimate its distance vector
40-
def bellman_ford(self, s) -> dict:
40+
def bellman_ford(self, s:str) -> dict:
4141
distances = {vertex: sys.maxsize - 1 for vertex in self.graph}
4242
distances[s] = 0
4343

@@ -51,7 +51,7 @@ def bellman_ford(self, s) -> dict:
5151
# perform the johnson algorithm to handle the negative weights that
5252
# could not be handled by either the dijkstra
5353
# or the bellman ford algorithm efficiently
54-
def johnson_algo(self) -> dict:
54+
def johnson_algo(self) -> list[dict]:
5555
self.add_vertices("#")
5656
for v in self.graph:
5757
if v != "#":

0 commit comments

Comments
 (0)