Question: Question 4 (16 points) - Pascal's Right Triangle If you multiply out expressions of the form (a + b) row, you get the following:
Question 4 (16 points) - Pascal's Right Triangle If you multiply out expressions of the form (a + b) row, you get the following: (a + b) = 1a + 1b (a+b)21a2+2ab+1b (a+b)3 = 1a3+3ab+3ab + 1b3 (a + b) 1a 4a3b+ 6ab + 4ab3 + 164 We can determine the colt coefficient of the rowth expression using Pascal's Triangle: row col 34 0 1 2 3 4 ... 111 2121 3 133 1 4146 41 Complete the method getCoefficient below so that it returns the number at the given row and col in Pascal's triangle. Use the following rules to guide you in your solution: a) If row and col identify a box outside the triangle, the coefficient is O b) If row is 1 (and col is valid), the coefficient is 1 c) Otherwise, the number at a given row and col is the sum of the number directly above it and the number above and to the left. For instance, the number at row 4 and column 3 is the sum of 1 and 3. Use recursion to find these numbers. Note: There is no array involved in this problem. // For example: calls to getCoefficient method (and the result) public static void main(String[] args) { System.out.println(getCoefficient (4, 3)); // prints 4. System.out.println(getCoefficient (3, 1)); // prints 3 System.out.println(getCoefficient (2, 3)); // prints } public static int getCoefficient (int row, int col) {
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
