Skip to content

Commit

Permalink
Fix mypy errors at mst_kruskal (TheAlgorithms#4581)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhihasan authored Aug 2, 2021
1 parent a5bcf0f commit da71184
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions graphs/minimum_spanning_tree_kruskal.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from typing import List, Tuple


def kruskal(num_nodes: int, num_edges: int, edges: List[Tuple[int, int, int]]) -> int:
def kruskal(
num_nodes: int, edges: list[tuple[int, int, int]]
) -> list[tuple[int, int, int]]:
"""
>>> kruskal(4, 3, [(0, 1, 3), (1, 2, 5), (2, 3, 1)])
>>> kruskal(4, [(0, 1, 3), (1, 2, 5), (2, 3, 1)])
[(2, 3, 1), (0, 1, 3), (1, 2, 5)]
>>> kruskal(4, 5, [(0, 1, 3), (1, 2, 5), (2, 3, 1), (0, 2, 1), (0, 3, 2)])
>>> kruskal(4, [(0, 1, 3), (1, 2, 5), (2, 3, 1), (0, 2, 1), (0, 3, 2)])
[(2, 3, 1), (0, 2, 1), (0, 1, 3)]
>>> kruskal(4, 6, [(0, 1, 3), (1, 2, 5), (2, 3, 1), (0, 2, 1), (0, 3, 2),
>>> kruskal(4, [(0, 1, 3), (1, 2, 5), (2, 3, 1), (0, 2, 1), (0, 3, 2),
... (2, 1, 1)])
[(2, 3, 1), (0, 2, 1), (2, 1, 1)]
"""
Expand Down Expand Up @@ -44,4 +43,4 @@ def find_parent(i):
node1, node2, cost = [int(x) for x in input().strip().split()]
edges.append((node1, node2, cost))

kruskal(num_nodes, num_edges, edges)
kruskal(num_nodes, edges)
4 changes: 2 additions & 2 deletions graphs/tests/test_min_spanning_tree_kruskal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def test_kruskal_successful_result():
num_nodes, num_edges = 9, 14
num_nodes = 9
edges = [
[0, 1, 4],
[0, 7, 8],
Expand All @@ -20,7 +20,7 @@ def test_kruskal_successful_result():
[1, 7, 11],
]

result = kruskal(num_nodes, num_edges, edges)
result = kruskal(num_nodes, edges)

expected = [
[7, 6, 1],
Expand Down

0 comments on commit da71184

Please sign in to comment.