Question: Python 3, Given a matrix of 0s and 1s that represent the state space of a search problem, we have a starting row and column

Python 3, Given a matrix of 0s and 1s that represent the state space of a search problem, we have a starting row and column given by a tuple (starting_row, starting_column), and a target row and column (target_row, target_column). Implement an algorithm that outputs the length of the shortest path from (starting_row, starting_column) to (target_row, target_column) where the path contains only 1 values along the way. Note that each location in the path (including the start and target), must be a 1. Each subsequent location in the path must be a 4-directionally adjacent to the previous (north, south, east, west). If the task is not possible, the algorithm should return -1. Examples: input: matrix = [[1, 1, 1, 1], [0, 0, 0, 1], [1, 1, 1, 1]] # list of lists in python starting_row = 0, starting_column = 0, target_row = 2, target_column = 0 output: 8 (The lines below represent this matrix:) 1111 0001 1111 ----------------------------------------------------------------------------------------------------------------------- matrix = [[1, 1, 1, 1], [0, 0, 0, 1], [1, 0, 1, 1]] starting_row = 0, starting_column = 0, target_row = 2, target_column = 0 output: -1 (The lines below represent this grid:) 1111 0001 1011

please send a screenshot of the output

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!