breadth-first search algorithm