Implement breadth-first search