Skip to content

Commit 05e92ef

Browse files
committed
removed redundant variable (self.nodes)
1 parent 3073d08 commit 05e92ef

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

graphs/minimum_spanning_tree_kruskal2.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,12 @@ def union(self, x: int, y: int) -> None:
4343
class GraphUndirectedWeighted:
4444
def __init__(self):
4545
# connections: map from the node to the neighbouring nodes (with weights)
46-
# nodes: counting the number of nodes in the graph
4746
self.connections = {}
48-
self.nodes = 0
4947

5048
def add_node(self, node: int) -> None:
5149
# add a node ONLY if its not present in the graph
5250
if node not in self.connections:
5351
self.connections[node] = {}
54-
self.nodes += 1
5552

5653
def add_edge(self, node1: int, node2: int, weight: int) -> None:
5754
# add an edge with the given weight
@@ -94,7 +91,7 @@ def kruskal(self) -> GraphUndirectedWeighted:
9491
num_edges = 0
9592
index = 0
9693
graph = GraphUndirectedWeighted()
97-
while num_edges < self.nodes - 1:
94+
while num_edges < len(self.connections) - 1:
9895
u, v, w = edges[index]
9996
index += 1
10097
parentu = disjoint_set.find_set(u)

0 commit comments

Comments
 (0)