Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Recursive Static Method Question..I really need help?

For this recursive method, there is an array (a)

This array (a) needs to be put in this code to make zigZag( a, 0, 0, 1) result in the greatest value.

I've read through this code and I think that "array(a)" value would be: a = { 0, 1, 2, 3, 4, 5 }

However, I cannot check because I do not have a Java compiler on my computer..I also am very inexperienced when it comes to reading computer codes.

Here is the code:

public static int zigZag( int[] a, int startIdx, int target, int inc )

{

int i;

for ( i = startIdx ; i >= 0 && i < a.length && target < a.length ; i += inc )

{

if ( a[ i ] == target )

return zigZag( a, i, target + 1, -inc );

}

if ( target == a.length )

return i;

else

return -1;

}

For which of these arrays a is the value of zigZag( a, 0, 0, 1 ) the greatest?

a = { 0, 1, 2, 3, 4, 5 }

a = { 3, 1, 2, 0, 5, 4 }

a = { 1, 0, 3, 5, 2, 4 }

a = { 5, 1, 3, 4, 0, 2 }

a = { 1, 4, 3, 5, 2, 0 }

Very much appreciated!

1 Answer

Relevance
Still have questions? Get your answers by asking now.