Question

Perform a box trace. Show trace int[] arr = {8, 10, 4, -2, 2, 8, 6,...

Perform a box trace. Show trace

int[] arr = {8, 10, 4, -2, 2, 8, 6, 4, 3, 9};

System.out.println(fun(arr, 7, 1));

int fun(int nums[], int aa, int bb) {

int ret;

System.out.println(aa);

if(aa <= 1)

ret = nums[bb];

else

ret = nums[bb-1] + fun(nums, aa - 2, bb +1);

System.out.println(ret);

return ret;

}

Homework Answers

Answer #1

arr[] = {8, 10, 4, -2, 2, 8, 6, 4, 3, 9}

fun(arr, 7, 1) returns arr[0] + fun(arr, 5, 2)

fun(arr, 5, 2) returns arr[1] + fun(arr, 3, 3)

fun(arr, 3, 3) returns arr[2] + fun(arr, 1, 4)

fun(arr, 1, 4) returns arr[4]

The output will be:

7
5
3
1
2
6
16
24
24

If you're still having any doubt then please feel free to ask in the comment section.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
evaluate each indefinite integral 4) \int -(2*csc^(2)2x)/(cot(2x)*\sqrt(cot^(2)2x-1)); u=cot2x 5)  \int (10x^(4))/(9+4x^(10)); u=2x^(5) 6) \int (20x^(3))/(\sqrt(25-25x^(8))) 7) \int...
evaluate each indefinite integral 4) \int -(2*csc^(2)2x)/(cot(2x)*\sqrt(cot^(2)2x-1)); u=cot2x 5)  \int (10x^(4))/(9+4x^(10)); u=2x^(5) 6) \int (20x^(3))/(\sqrt(25-25x^(8))) 7) \int (1)/(x\sqrt(25-(ln-2x)^(2)))
Write a recursive method public static int sumEveryOther(int n) that takes a positive int as an...
Write a recursive method public static int sumEveryOther(int n) that takes a positive int as an argument and returns the sum of every other int from n down to 1. For example, the call sumEveryOther(10) should return 30, since 10 + 8 + 6 + 4 + 2 = 30. The call sumEveryOther(9) should return 25 since 9 + 7 + 5 + 3 + 1 = 25. Your method must use recursion.
please wirte the mips code main() { x = 2*foo(4*y+7); x = x+(4*y+7); } int foo...
please wirte the mips code main() { x = 2*foo(4*y+7); x = x+(4*y+7); } int foo (int n) { int junk[10] = {0,1,2,3,4,5,6,7,8,9}; junk[4] += 2; if (n<1) return 1; else return (foo(n-1) + junk[4] + n); }
Let p = (8, 10, 3, 11, 4, 0, 5, 1, 6, 2, 7, 9) and...
Let p = (8, 10, 3, 11, 4, 0, 5, 1, 6, 2, 7, 9) and let q = (2, 4, 9, 5, 10, 6, 11, 7, 0, 8, 1, 3) be tone rows. Verify that p = Tk(R(I(q))) for some k, and find this value of k.
Q.8 (a) Using the information contained in the table below, calculate the accounting rate of return(ARR),...
Q.8 (a) Using the information contained in the table below, calculate the accounting rate of return(ARR), showing all your working for both projects: Year Project A Project B (100) (100) 0 20 35 1 25 35 2 35 30 3 25 15 4 25 10 5 25 10 6 10 - (b)Explain the advantages and disadvantages of the accounting rate of return(ARR).[ 20 marks
For the following set of scores: 8 6 7 5 4 10 8 9 5 7...
For the following set of scores: 8 6 7 5 4 10 8 9 5 7 2 9 9 10 7 8 8 7 4 6 3 8 9 6 a. Construct a frequency distribution table. b. Sketch a histogram showing the distribution. c. Describe the distribution using the following characteristics: (1) What is the shape of the distribution? (2) What score best identifies the center (average) for the distribution? (3) Are the scores clustered together, or are they spread...
There will be a total of 16 minerals (7 major & 9 trace) Minerals Name –...
There will be a total of 16 minerals (7 major & 9 trace) Minerals Name – both name and number if given Function Major or trace if minerals 4 food sources Name of deficiency or symptoms of deficiency Toxicity Yes or no 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16.
15 students received the following scores on a quiz. 6, 7, 2, 10, 8, 6, 7,...
15 students received the following scores on a quiz. 6, 7, 2, 10, 8, 6, 7, 3, 9, 5, 5, 8, 9, 8, 4 1. What is the cumulative frequency for students who scored 6? 2. How many students scored between 7 and 10? 3. What is the cumulative percentage for students who scored 9? 4. A student who received a score of 7 would be at what percentile? (approximately)
Consider the following: period 1, 2, 3, 4, 5, 6, 7, 8 demand 7, 8, 9,...
Consider the following: period 1, 2, 3, 4, 5, 6, 7, 8 demand 7, 8, 9, 10, 14, 16, 13, 16 a. using a trend projection, forecast the demand for period 9 b. calculate the MAD for this forecast Show all work! do not use excel or phstat!!!
x f 10 3 9 6 8 4 7 5 6 2 Find the Z score...
x f 10 3 9 6 8 4 7 5 6 2 Find the Z score when X = 9, for the for the following Data