Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 5 This lab is to be completed individually This lab is for you to understand recursion. Please find two files ArraySum.java, NodeStacking.java and fill

Lab 5 This lab is to be completed individually This lab is for you to understand recursion. Please find two files ArraySum.java, NodeStacking.java and fill the method body. What to do? 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 0 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 theres a structure as follows. Each row of nodes is stacked together to form a pyramid. Each node weighs 128 ponds, 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 I 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 As weight and the weight its 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

a. Describe the encounter. What made it intercultural?

Answered: 1 week ago