Skip to content

Commit 96382d1

Browse files
authored
Added type hints and return types for the function
1 parent e4cb145 commit 96382d1

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

graphs/floyd_warshall.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
Wiki page:- <https://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm>
1313
"""
1414

15-
16-
def floyd_warshall(graph, n):
15+
def floyd_warshall(graph: list[list], num_nodes: int) -> list[list]:
1716
"""
1817
Returns the shortest distance between all pairs of nodes
1918
@@ -37,14 +36,13 @@ def floyd_warshall(graph, n):
3736
"""
3837
# The graph is a Adjancecy matrix (see <https://en.wikipedia.org/wiki/Adjacency_matrix>)
3938
distance: list[list] = graph
40-
for k in range(n):
41-
for i in range(n):
42-
for j in range(n):
39+
for k in range(num_nodes):
40+
for i in range(num_nodes):
41+
for j in range(num_nodes):
4342
distance[i][j] = min(distance[i][j], distance[i][k] + distance[k][j])
4443
return distance
4544

46-
47-
if __name__ == "__main__":
45+
if __name__ == '__main__':
4846
"""
4947
Layout of G:-
5048
2 2 1 1 5

0 commit comments

Comments
 (0)