Skip to content

Commit d9b07df

Browse files
authored
Update minimum_spanning_tree_kruskal2.py
1 parent 22083ae commit d9b07df

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

graphs/minimum_spanning_tree_kruskal2.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
from __future__ import annotations
22

3-
from typing import Generic, TypeVar
4-
5-
T = TypeVar("T")
6-
7-
8-
class DisjointSetTreeNode(Generic[T]):
3+
class DisjointSetTreeNode[T]:
94
# Disjoint Set Node to store the parent and rank
105
def __init__(self, data: T) -> None:
116
self.data = data
127
self.parent = self
138
self.rank = 0
149

1510

16-
class DisjointSetTree(Generic[T]):
11+
class DisjointSetTree[T]:
1712
# Disjoint Set DataStructure
1813
def __init__(self) -> None:
1914
# map from node name to the node object
@@ -46,7 +41,7 @@ def union(self, data1: T, data2: T) -> None:
4641
self.link(self.find_set(data1), self.find_set(data2))
4742

4843

49-
class GraphUndirectedWeighted(Generic[T]):
44+
class GraphUndirectedWeighted[T]:
5045
def __init__(self) -> None:
5146
# connections: map from the node to the neighbouring nodes (with weights)
5247
self.connections: dict[T, dict[T, int]] = {}
@@ -118,4 +113,5 @@ def kruskal(self) -> GraphUndirectedWeighted[T]:
118113
num_edges += 1
119114
graph.add_edge(u, v, w)
120115
disjoint_set.union(u, v)
116+
# Return the generated Minimum Spanning Tree
121117
return graph

0 commit comments

Comments
 (0)