BFS and DFS algorithms on a maze