Skip to content

Commit 80ee47d

Browse files
Merge pull request #384 from hbostann/bfs-python-comments
Added comments to python implementation of BFS
2 parents 2d4dcc0 + 13f184e commit 80ee47d

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

BFS/bfs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33

44
def bfs(graph, root):
55
visited, queue = set(), collections.deque([root])
6+
# While we still have nodes to visit
67
while queue:
78
vertex = queue.popleft()
9+
# Add neighbours of current node to queue if they
10+
# haven't been visited yet and mark them as visited.
811
for neighbour in graph[vertex]:
912
if neighbour not in visited:
1013
visited.add(neighbour)

0 commit comments

Comments
 (0)