For the questions below, consider the following representation of grid and the maze code from Chapter 11.
Grid:
1 1 1 1 1 1 0 0
0 0 1 0 0 1 0 0
0 0 1 0 0 1 1 0
0 0 1 1 0 0 1 0
0 0 0 1 1 0 0 0
0 0 0 0 1 1 1 1
Code:
public boolean traverse(int row, int column)
{
if (valid(row, column) )
{
boolean done = false;
grid[row][column] = TRIED;
if (row == grid.length - 1 && column == grid[0].length - 1)
done = True;
else
{
done = traverse(row + 1, column) ;
if (!done) done = traverse(row, column + 1) ;
if (!done) done = traverse(row - 1, column) ;
if (!done) done = traverse(row, column - 1) ;
}
if (done) grid[row][column] = PATH;
}
return done;
}
Assume valid returns True if row and column are >= 0 and <= the grid's row length or column length and the entry at this position = = 1. And assume TRIED = 3 and PATH = 7
-If traverse is first called with traverse(0, 0) ; what will the first recursive call of traverse be?
A) traverse(0, 0) ;
B) traverse(0, 1) ;
C) traverse(1, 0) ;
D) traverse(1, 1) ;
E) traverse(0, -1) ;
Correct Answer:
Verified
Q4: The following two methods will both compute
Q9: The following method lacks a base case.
public
Q18: For the questions below, recall the Towers
Q18: A recursive method without a base case
Q19: For the questions below, assume that int[
Q20: What does the following recursive method determine?
Public
Q25: Define the magnitude of a number as
Q26: Aside from writing recursive methods, another way
Q27: The following method recognizes whether a String
Q28: An infinite loop and an infinite recursion
A)
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents