Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update bfs_exercise_solution.py
  • Loading branch information
nikhilailani authored Dec 24, 2020
commit 8d9b988e9d8f3baf415a52cd16caed44b2b281e2
8 changes: 3 additions & 5 deletions algorithms/9_BreadthFirstSearch/bfs_exercise_solution.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
def bfs(data, start, end, visited=[]):
queue = [start]

while queue:
current_node = queue.pop(0)
if current_node==end:
print("Path exists!")
print("Path: " + "->".join(visited) + "->" + end)
return
visited.append(current_node)

for i in data[current_node] - set(visited):
queue.append(i)
print("Path does not exist!")
return




if __name__ == '__main__':
data = {
'A': {'B'},
Expand Down