Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the code need to fill. public class ArraySum { /** * Implement a recursive method that takes an integer array, two indices as

image text in transcribedimage text in transcribedHere is the code need to fill.

public class ArraySum { /** * Implement a recursive method that takes an integer array, two indices as arguements * calulate the sum from start to end of the array, and return the result. */ public static int arrSum(int[] arr, int start, int end) { // Filling your code here

// End of your code } }

Second file is:

public class NodeStacking { // use this weight for calculating public static int weight = 128;

/** * Implement a recursive method that takes row index and column index of a node. * calculate the weight it supports. */ public static double weightSupporting(int row, int col) { // Filling your code here

// End of your code } }

Thanks for helping me!

Task 1 Design and implement a recursive method for calculating the sum of an integer 1D-array with given start and end index. If the input index is invalid, please return O instead. For example, Input: [1,2,3,4,5,6], 2,5 Output: 18 Input:[1,2,3,4,5,6], -1,8 Output: 0 Task 2 Suppose there's a structure as follows. Each row of nodes is stacked together to form a pyramid. Each node weighs 128 pounds, and splits its weight evenly on the two nodes below it in the pyramid. For example, node A splits its weight across node B and node C. Node F splits its weight, plus the accumulated weight of the nodes it is supporting, onto node 1 and node J. Suppose this structure has infinite rows. The goal is to design and implement a recursive method that calculates how much weight a given node is supporting by specifying its row index and column index. Both indices start from 0, and each row has exact row index + 1 nodes. i.e. A is in row 0, column 0. F is in row 2, column 2. Your method should return -1 if the input indices are invalid. For example, Input 0, 0 which represents A, the output should be 0 Input 0, 1, which is an invalid index. The output should be -1 Input 1, 1, which is C. The supported weight should be the half of A's weight and the weight it's carrying. 1/2 * (128 + 0) = 64. Thus, output should be 64. Please put your code between /* #. Filling your code here */ and /* #. End of code *). Follow the instructions in comments carefully. Do not change the code or structure outside the blocks. Make your own test cases to test the program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Is how things are said consistent with what is said?

Answered: 1 week ago

Question

Do you currently have a team agreement?

Answered: 1 week ago

Question

c. How is trust demonstrated?

Answered: 1 week ago