@@ -32,7 +32,7 @@ def add_vertices(self, vertex: str) -> None:
3232 # assign weights for each edges formed of the directed graph
3333 def add_edge (self , vertex_a : str , vertex_b : str , weight : int ) -> None :
3434 """
35- Adds a directed edge from vertex `vertex_a`
35+ Adds a directed edge from vertex `vertex_a`
3636 to vertex `vertex_b` with weight `weight`.
3737 >>> g = JohnsonGraph()
3838 >>> g.add_vertices("A")
@@ -49,7 +49,7 @@ def add_edge(self, vertex_a: str, vertex_b: str, weight: int) -> None:
4949 # perform a dijkstra algorithm on a directed graph
5050 def dijkstra (self , start : str ) -> dict :
5151 """
52- Computes the shortest path from vertex `start`
52+ Computes the shortest path from vertex `start`
5353 to all other vertices using Dijkstra's algorithm.
5454 >>> g = JohnsonGraph()
5555 >>> g.add_vertices("A")
@@ -80,7 +80,7 @@ def dijkstra(self, start: str) -> dict:
8080 # carry out the bellman ford algorithm for a node and estimate its distance vector
8181 def bellman_ford (self , start : str ) -> dict :
8282 """
83- Computes the shortest path from vertex `start` to
83+ Computes the shortest path from vertex `start` to
8484 all other vertices using the Bellman-Ford algorithm.
8585 >>> g = JohnsonGraph()
8686 >>> g.add_vertices("A")
@@ -111,7 +111,7 @@ def bellman_ford(self, start: str) -> dict:
111111 # or the bellman ford algorithm efficiently
112112 def johnson_algo (self ) -> list [dict ]:
113113 """
114- Computes the shortest paths between
114+ Computes the shortest paths between
115115 all pairs of vertices using Johnson's algorithm
116116 for a directed graph.
117117 >>> g = JohnsonGraph()
@@ -161,10 +161,10 @@ def johnson_algo(self) -> list[dict]:
161161 for vertex1 in self .graph :
162162 new_dist = self .dijkstra (vertex1 )
163163 for vertex2 in self .graph :
164- if new_dist [vertex2 ] < sys .maxsize - 1 :
164+ if new_dist [vertex2 ] < sys .maxsize - 1 :
165165 new_dist [vertex2 ] += hash_path [vertex2 ] - hash_path [vertex1 ]
166166 for key in new_dist :
167- if new_dist [key ] == sys .maxsize - 1 :
167+ if new_dist [key ] == sys .maxsize - 1 :
168168 new_dist [key ] = None
169169 distances .append (new_dist )
170170 return distances
0 commit comments