Question: Your goal is to write a Python function that finds the shortest walking distance from a starting point (S: start) to the bottom-left corner(T: target)

Your goal is to write a Python function that finds the shortest walking distance from a starting point (S: start) to the bottom-left corner(T: target) of the grid. The grid is represented as a two-dimensional array(list) where 0 represent no obstacle and 1 represent obstacle at the corresponding location. For the example grid above, the array representation is as follows: G = [[0, 1, 0, 1, 0, 0 ], [0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0], [0, 0, 0, 1, 1, 0]] If the number of rows in the grid is n and the number of columns is m, your starting point is (0, 0) and the target is (n-1, m-1). In this example, you start from (0, 0) and want to reach to (3, 5). You can only move to left, right, up and down as long as there is no obstacle and you dont move outside of the grid as you can see in the following example. Write a function named find_shortest_path. Input: Two - dimensional array(G) that represents the grid. Output: Print the minimum number of steps needed to go from S to T and the actual path. If there is no valid path, report it as well( Minimum Steps: 0, Path: No Valid Path ) For the example above, a possible output is: Minimum Steps: 10 Path: (0, 0)=>(1, 0)=>(2, 0)=>(2, 1)=>(2, 2)=>(2, 3)=>(1, 3)=>(1, 4)=>(1, 5)=>(2, 5)=>(3, 5) You are required solve this problem with a graph algorithm. Represent this grid and possible moves with a graph. Essentially, each grid location is represented by a node and the possible moves are represented by edges. Once you create the graph, simply implement breadth-first search (BFS) algorithm to find the shortest path from the node that represents S to the node that represents T. You are NOT allowed to use any Python graph library or package such as a network in this assignment. Create your own graph representation (use an adjacency list representation) and implement BFS algorithm yourself. Implement and submit the following function that performs the task as described above. We will test it for various grid configurations. def find_shortest_path( G): // your code goes here

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!