BFS and DFS solutions