Completed Breadth-First Searching algorithm