Update breadth-first-search algorithm