Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Q8...IN JAVA Answer the two questions in brown under In Class Exercise 8: simply type your responses public class Manhattan f public static void main
Q8...IN JAVA
Answer the two questions in brown under In Class Exercise 8:
simply type your responses
public class Manhattan f public static void main (String[] argv) // Test case 1: go from (1,1) to (0,0) int n=countPaths (r, c); system . out . print In ("r-" + r + " c " + c + " n" + n); // Test case 2: go from (2,2) to (0,0) r-2; n = countPaths (r, c) ; system . out . print In ("re" + r + " c " + c + " n" + n); // Test case 2: go from (5,7) to (0,0) n - countPaths (r, c); system . out . print In ("re" + r + " c " + c + " :-n" + n); static int countPaths (int numRows, nt numcols) /7 Bottom out case: there's only one way to (0,0) // Note: it' and not && if ( (numRows 0) 11 (numcols-0) ) { return 1; // Otherwise, reduce to two sub-problems and add int downCount - countPaths (numRows-1, numCols); int rightCount - countPaths (numRows, numCols-1); return (downCount + rightcount); Note: The recursive method countPaths () has two recursive calls o The first one creates the sub-problem with fewer rows int downCount = countPaths (numRows-1, numCols); o The second creates the sub-problem with fewer columns int rightCount countPaths (numRows, numCols-1); In-Class Exercise 8: Consider the code above: Why is it that we need (OR) in the if condition? What would happen if we replaced that with && (AND)? So, in fact, how many ways are there to get from the corner of Park and 55-th to the corner of 2nd and 50th
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started