Last active
June 6, 2020 06:55
-
-
Save wilderfield/e7b4abc42af01c84b2e2de35f0df4066 to your computer and use it in GitHub Desktop.
BFS Iterative
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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