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
A.6 ... static int x = 1; int y = x * 2; void t1() {...
A.6 ... static int x = 1; int y = x * 2; void t1() {                 y++;                 cout << "x: " << x << " | y: " << y << endl;                 y += 1;                 x -= -1; } void t2() {                 int* x = &y;                 cout << "x: " << x << " | y: " << y << endl; } void t3() {                 int y = x;                 static int x...
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)))
Java question Consider the following: 1 class SnoopDogg { 2 int count; 3 } 4 class...
Java question Consider the following: 1 class SnoopDogg { 2 int count; 3 } 4 class Test { 5 public static void main ( String [] args ) { 6 SnoopDogg myCount = new SnoopDogg (); 7 myCount.count = 0; 8 int times = 0; 9 increment( myCount, times ); 10 System.out.println( myCount.count ); 11 System.out.println( times ); 12 } 13 public static void increment (SnoopDogg sd, int times ) { 14 sd.count = sd.count + 1; 15 times =...
Given this array: int sequence[10] = { 3, 4, 5, 6, 7, 8, 9, 10, 1,...
Given this array: int sequence[10] = { 3, 4, 5, 6, 7, 8, 9, 10, 1, 2 }; Write a C++ program to ask the user to enter a number, if the number can be found in the array, your program should display "Found". Otherwise, your program should display "Not found". For example, if the user enters 7, your program should display "Found". If the user enters 11, your program should display "Not found".
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); }
import java.util.Scanner; import java.util.Random; public class DiceRoll {    public static final int SIDES = 6;...
import java.util.Scanner; import java.util.Random; public class DiceRoll {    public static final int SIDES = 6;    public static void main(String[] args) {        // TODO Auto-generated method stub        System.out.println("Enter the number of times a 6 sided die should be rolled ");        Scanner keyboard = new Scanner(System.in);        Random r = new Random();               int times = keyboard.nextInt();        boolean valid = false;        while(!valid) {           ...
static int F(int n) { if (n < 1) return 1; else return 2*F(n-1)+n; } (a)...
static int F(int n) { if (n < 1) return 1; else return 2*F(n-1)+n; } (a) [7 points] Give the recurrence that describes the running time of F(int n). (b) [8 points] Solve the recurrence equation from (a). Note: For (b), you must show your work
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.
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...