Question: Robots on Grids Let's consider a robot on an m x n grid of squares ( that is , m rows and n columns )
Robots on Grids
Let's consider a robot on an grid of squares that is rows and columns The robot starts in the topleft square, and its target is at the bottomright. The robot has two moves available to it it can move one square to the right, or one square down so it must make a combination of rightward and downward moves to reach its target. It follows that the robot will take steps to reach its target.
Here are two such paths it could take:
Your task is to write code that counts the number of possible paths for the robot, given an and
Write a function num paths that recursively computes the number of paths from the topleft to bottomright square of an grid without memoization.
Write a function numpathsmemo that does the same, but memoizes the smaller subproblem solutions.
The provided sampledriver code will
import time
def numpaths :
# TODO: Task of the assignment
def numpathsmemom n:
# TODO: Task of the assignment
#driver code you do not need to make any changes after this line.
#However, submit a screenshot of the output to report the execution timeelapsed time.
starttime time.time
print numpaths
endtime time.time
starttimememo time.time
printnumpathsmemo do the runtime calculation for you. Take a screenshot of the output and submit it along with your python script.
Expectef Output
The expected result for m n is
The elapsed timeruntime can vary from system to system.
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
