Skip to content

Instantly share code, notes, and snippets.

@wilderfield
Last active June 6, 2020 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilderfield/e7b4abc42af01c84b2e2de35f0df4066 to your computer and use it in GitHub Desktop.
Save wilderfield/e7b4abc42af01c84b2e2de35f0df4066 to your computer and use it in GitHub Desktop.
BFS Iterative
def bfsIterative(node,visited=set()):
queue = [node]
while queue:
node = queue.pop(0) # Pop first node in list
if node not in visited:
visited.add(node)
# Process this node here
for neighbor in getNeighbors(node):
if neighbor not in visited:
queue.append(neighbor)
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment