Question: 5 . Apply BFS / DFS / MST to solve a problem ( Portfolio Project Problem ) : You are given a 2 - D
Apply BFSDFSMST to solve a problem Portfolio Project Problem:
You are given a D puzzle of size MxN that has N rows and M column M and N can be
different Each cell in the puzzle is either empty or has a barrier. An empty cell is marked by
hyphen and the one with a barrier is marked by # You are given two coordinates from
the puzzle ab and xy You are currently located at ab and want to reach xy You can
move only in the following directions.
L: move to left cell from the current cell
R: move to right cell from the current cell
U: move to upper cell from the current cell
D: move to the lower cell from the current cell
You can move to only an empty cell and cannot move to a cell with a barrier in it Your goal
is to reach the destination cells covering the minimum number of cells as you travel from the
starting cell.
Example Board:
#
# # #
#
Input: board, source, destination.
Puzzle: A list of lists, each list represents a row in the rectangular puzzle. Each
element is either for empty passable or # for obstacle impassable The same
as in the example.
Example:
Puzzle
#
###
#
source: A tuple representing the indices of the starting position, eg for the upper
right corner, source
destination: A tuple representing the indices of the goal position, eg for the lower
right corner, goal
Output: A list of tuples representing the indices of each position in the path. The first tuple
should be the starting position, or source, and the last tuple should be the destination. If
there is no valid path, None should be returned. Not an empty list, but the None object.
If source and destination are same return the same cell.
Note: The order of these tuples matters, as they encode a path. Each position in the path
must be empty correspond to a on the board and adjacent to the previous position.
Example consider above puzzle
Input: puzzle,
Output:
Example consider above puzzle
Input: puzzle,
Output:
Example : consider above puzzle
Input: puzzle,
Output: None
Example : consider above puzzle
Input: puzzle,
Output:
a Describe an algorithm to solve the above problem.
b Implement your solution in a function solvepuzzleBoard Source, Destination Name your
file Puzzle.py
c What is the time complexity of your solution?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
