grokking-algorithms/chapter6
2024-02-06 21:53:17 +00:00
..
bfs1.png add bfs 2024-01-11 18:28:03 +00:00
bfs2.png add bfs 2024-01-11 18:28:03 +00:00
ex6.1.py use set for visited 2024-01-11 18:54:08 +00:00
ex6.2.py use set for visited 2024-01-11 18:54:08 +00:00
mango.py add mango 2024-01-11 19:09:17 +00:00
README.md clean up repo. 2024-02-06 21:53:17 +00:00

Breadth-First Search

Can tell you if there's a path between A and B and will find the shortest.

In these examples, 1st degree Mango sellers are found before 2nd degree, 2nd before 3rd and so on.

Visted nodes should be stored in a set to ensure no infinite loops.

Running time for BFS on a directed graph: O(V + E) where V = vertices, E = edges.