We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f8ab93b commit 28a6ce5Copy full SHA for 28a6ce5
1 file changed
graphs/graph_algorithms.py
@@ -46,13 +46,13 @@ def undirected_connected_components(gr):
46
in an undirected graph """
47
if gr.DIRECTED:
48
raise Exception("This method works only with a undirected graph")
49
- explored = []
+ explored = set([])
50
con_components = []
51
for node in gr.nodes():
52
if node not in explored:
53
reachable_nodes = BFS(gr, node)
54
con_components.append(reachable_nodes)
55
- explored += reachable_nodes
+ explored |= reachable_nodes
56
return con_components
57
58
def DFS(gr, s):
0 commit comments