do_bfs function

Use the breadth-first search (bfs) algorithm