Question: Maze problem: A binary matrix is given say B, the task is to find a sequence of moves from a given initial location (X0, Y0)
Maze problem: A binary matrix is given say B, the task is to find a sequence of moves from a given initial location (X0, Y0) in the matrix, to a final location (Xn, Yn) explicitly using stack. Ex: 0 0 1 0 0 1 1 1 0 1 1 1 1 1 0 1 0 0 1 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 0 1 0 1 1 0 0 The initial position X0, Y0 has 1 as the element. A move can be made to a location; only if there is 1 in the neighboring co-ordinate (only 4- neighbors are considered ignoring diagonal neighbors). In the above example from initial location (0,2) the possible move is (1,2). From (1, 2) the possible moves are (0,2), (1,3), (1,1) and (2,2). So the expected output for the input (0,2) as start and (7,4) as the destination is, a sequence (0,2)(1,2)(2,2)(3,2)(3,3)(3,4)(3,5)(3,6)(4,6)(5,6)(6,6)(6,5) (7,5)(7,4). There can be similar other paths.
Maze problem: A binary matrix is given say B, the task is to find a sequence of moves from a given initial location (Xo, Yo) in the matrix, to a final location (Xn, Yn) explicitly using stack. Ex: 0 0 1 0 1 1 1 1 0 1 0 0 1 0 0 0 0 1 Intial Location (Xo, Yo)-(0, 2) 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 (1 Final Location (Xn, %)=(7, 4) 0 The initial position Xo, Yo has 1 as the element. A move can be made to a lpcation; only if there is 1 in the neighboring co-ordinate (only 4- neighbors are considered ignoring diagonal neighbors). In the above example from initial location (0,2) the possible move is (1,2). From (1, 2) the possible moves are (0,2), (1,3), (1,1) and (2,2). So the expected output for the input (0,2) as start and (7,4) as the destination is, a sequence There can be similar other paths
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
