Big and Tasty
2012-04-02 06:54:54 UTC
public static int search( String[] array, String target )
{
Random p = new Random();
int r = 0;
while ( !target.equals( array[ r ] ) )
{
r = p.nextInt( array.length );
}
return r;
}
Exactly one of these statements is true. Which one?
A. This method will only work if the target is the first element of the array.
B. On average, this method will perform better when the array is unsorted.
C. There are target values for which this method will never return a value.
D. A sequential search of the same array will always perform better than this method.
E. This method will make at most k iterations, where k is the length of the array.