Limited access

Upgrade to access all content for this subject

Consider the following method.

public static int search(int x[], int key)
{
    int i = (int)(Math.random()*(x.length));
    while (x[i] != key)
        i = (int)(Math.random()*(x.length));
    return i;
}

Which of the following conditions will ALWAYS cause this method to get into an infinite loop?

A

key is greater than the number of elements in x.

B

key is not found in x.

C

x has all the same values.

D

x has multiple elements equal to key.

E

x is not sorted.

Select an assignment template