Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vishnu1991/c2e449b520b7cdf2481583d3125c9afd to your computer and use it in GitHub Desktop.
Save vishnu1991/c2e449b520b7cdf2481583d3125c9afd to your computer and use it in GitHub Desktop.
BFS(source, goal):
queue = empty new queue
queue.add(source)
if current == goal:
return path
if current in visited:
continue
visited.add(current)
for direction, neighbour in graph[current]:
queue.append((path + direction, neighbour))
return "NO WAY!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment