We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 88bba55 commit 13f184eCopy full SHA for 13f184e
BFS/bfs.py
@@ -3,8 +3,11 @@
3
4
def bfs(graph, root):
5
visited, queue = set(), collections.deque([root])
6
+ # While we still have nodes to visit
7
while queue:
8
vertex = queue.popleft()
9
+ # Add neighbours of current node to queue if they
10
+ # haven't been visited yet and mark them as visited.
11
for neighbour in graph[vertex]:
12
if neighbour not in visited:
13
visited.add(neighbour)
0 commit comments