Question: Hi! I have this Java programming question dealing with recursion for my Data Structures course. I have some of it completed but am having trouble
Hi! I have this Java programming question dealing with recursion for my Data Structures course. I have some of it completed but am having trouble with finishing it. If someone could correct any errors I may have made and help me finish it that would be awesome! Thanks!
int[][] toll = {
{6, 4, 7, 4, 8, 3, 6, 7, 2, 4},
{9, 1, 4, 7, 3, 6, 8, 6, 1, 4},
{4, 8, 1, 9, 7, 9, 2, 3, 5, 4},
{1, 8, 6, 6, 8, 4, 8, 3, 8, 2},
{7, 3, 7, 4, 4, 1, 5, 9, 9, 4},
{1, 6, 3, 2, 1, 4, 3, 3, 7, 9},
{5, 3, 8, 4, 2, 6, 7, 9, 2, 5},
{6, 4, 3, 8, 7, 1, 2, 4, 7, 4},
{8, 8, 3, 6, 5, 8, 3, 9, 1, 5},
{0, 3, 5, 6, 1, 2, 7, 1, 9, 4}};
for (int i = 0; i
System.out.println("Minimum at " + i + "is: " + minRec(toll, i));
}
}
public static int minRec(int[][] arr, int col) {
return minToll(arr, 0, col);
}
private static int minToll(int[][] array, int row, int column) {
if (row == 9) {
return array[row][column];
} else if (column == 0) {
return array[row][column] * Math.min(minToll(array, row + 1, column), minToll(array, row + 1, column + 1));
} else if (column == 9) {
return array[row][column] * Math.min(minToll(array, row + 1, column - 1), minToll(array, row + 1, column));
} else {
return array[row][column] * min(minToll(array, row - 1, column - 1), minToll(array, row + 1, column), minToll());
}
}

24. Each square of the following1 paid when you enter the square. You wish to travel som the bottom-most row to the top- most row and minimize the total of the tolls along the way. Write a program to output the row and column numbers of a route that minimizes the tolls. When making a move, the row number must increase by 1 and the column number can change by , 0, or +1. Tolls range from 0 to 9, and row 1 and column 1 is the lower leftmost square of the checkerboard. The
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
