Skip to content

Commit 28a6ce5

Browse files
committed
union two sets in undirected_connected_components
1 parent f8ab93b commit 28a6ce5

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

graphs/graph_algorithms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ def undirected_connected_components(gr):
4646
in an undirected graph """
4747
if gr.DIRECTED:
4848
raise Exception("This method works only with a undirected graph")
49-
explored = []
49+
explored = set([])
5050
con_components = []
5151
for node in gr.nodes():
5252
if node not in explored:
5353
reachable_nodes = BFS(gr, node)
5454
con_components.append(reachable_nodes)
55-
explored += reachable_nodes
55+
explored |= reachable_nodes
5656
return con_components
5757

5858
def DFS(gr, s):

0 commit comments

Comments
 (0)