BFS modifies the graph


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,

1 Like

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: