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
I need to get the Min and Max value of an array when a user inputs...
I need to get the Min and Max value of an array when a user inputs values into the array. problem is, my Max value is right but my min value is ALWAYS 0. how do i fix this? any help please!!! _________________________________________________________________________________________________ import java.util.Scanner; public class ArrayMenu{ static int count; static Scanner kb = new Scanner(System.in);             public static void main(){ int item=0; int[] numArray=new int[100]; count=0;       while (item !=8){ menu(); item = kb.nextInt();...
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)))
Consider the following array: int[] a = { 3, 5, 2, 2, 4, 7, 0, 8,...
Consider the following array: int[] a = { 3, 5, 2, 2, 4, 7, 0, 8, 9, 4 }; What are the contents of the array a after the following loops complete? (show how you arrive at the answer) a) for (int i = 1; i < 10; i++) { a[i] = a[i - 1]; b) for (int i = 9; i > 0; i--) { a[i] = a[i - 1]; }
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 =...
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 =...
class Ex1{ 2. public static void main(String args[]){ 3. int x = 10; 4. int y...
class Ex1{ 2. public static void main(String args[]){ 3. int x = 10; 4. int y = new Ex1().change(x); 5. System.out.print(x+y); 6. } 7. int change(int x){ 8. x=12; 9. return x; 10. } 11. } Can you please explain this entire code and what is happening?
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".
import java.io.PrintStream; import java.util.Arrays; public class joker { public static int smallest(int[] v1, int[] v2) {...
import java.io.PrintStream; import java.util.Arrays; public class joker { public static int smallest(int[] v1, int[] v2) { return 0; } public static int[] convert1(String str) { return new int[1]; } public static String convert2(int[] v) { return ""; } public static void main(String[] args) { testSmallest(); testConvert(); } public static void testSmallest() { System.out.println("Testing your method smallest(...)"); int[][] testVectors1 = new int[][]{{1, 2, 3}, {1, 2, 3, 4}, {1, 2, 3}, {1, 2, 3}, {2, 3, 4}}; int[][] testVectors2 = new...
Operator exercises: int x; x = 8/3; x = 11 % 4; x = 31%10; x...
Operator exercises: int x; x = 8/3; x = 11 % 4; x = 31%10; x = 1/2; x = 5/3; x = 5.0/3; x = 12 - 4 / 3 ā€“ 8 * 2; x = 24 / 5 + 1 * 4; x = 12 - 9 + 4 * 2 + 3 % 2; x = 2 * (5 - 3) + 7;   Assume the following order of operations: ! && || Give the value of x,...