educative.io

BFS modifies the graph

Hi,

print(bfs(g, 0)) #02143
print(bfs(g, 0)) #0

I think we should use a temporary variable while getting the adjacent nodes.
temp = my_graph.graph[source]

Best Regards,
Jithu

Hi @Jithu_Sunny. You are right. The original graph was getting modified. Thanks for pointing out the mistake in our algorithm. There was a mistake from our side, and it has been updated successfully. Happy Learning :smiley: