Given a 2D maze, write two separate functions implementing DFS and BFS to find the destination. 1 represents a wall, 0 represents an empty cell.
Testcase:
maze = [
[1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 1, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 1, 0, 1],
[1, 1, 1, 0, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1],
]
start = (1, 5)
end = (2, 3)The expected output for DFS is:
(1, 5),(1, 4),(2, 4),(2, 1),(1, 1),(1, 2),(3, 2),(3, 1),(3, 3),(2, 3)The expected output for BFS is:
(1, 5),(1, 4),(2, 4),(2, 1),(3, 1),(3, 3),(2, 3)Can someone please help me with this? I am simply not understanding why it goes from (2, 4) to (2, 1) in both cases.
UPDATE: I forgot to include this:
Consider the following as the preference of direction when traversing the maze: left, right, up, down.