Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MFDBS 91 3rd Symposium On Mathematical Fundamentals Of Database And Knowledge Base Systems Rostock Germany May 6 9 1991

Authors: Bernhard Thalheim ,Janos Demetrovics ,Hans-Detlef Gerhardt

1991st Edition

3540540091, 978-3540540090

More Books

Students also viewed these Databases questions

Question

Describe how early experiences can modify the brain.

Answered: 1 week ago

Question

2. Describe how technology can impact intercultural interaction.

Answered: 1 week ago