0:00

What would the following code return from `mystery([90, -30, 50], 50)`?

```public static int mystery(int[] elements, int target)
{
for (int j = 0; j < elements.length; j++)
{
if (elements[j] == target)
{
return j;
}
}
return -1;
}```

4

What would the following code return from `mystery([90, -30, 50], -20)`?

``` public static int mystery(int[] elements, int target)
{
for (int j = 0; j < elements.length; j++)
{
if (elements[j] == target)
{
return j;
}
}
return -1;
}```

1

Consider the `binarySearch` method below. How many times would the while loop execute if you first do `int[] arr = {2, 10, 23, 31, 55, 86}` and then call `binarySearch(arr,2)`?

```public static int binarySearch(int[] elements, int target) {
int left = 0;
int right = elements.length - 1;
while (left <= right)
{
int middle = (left + right) / 2;
if (target < elements[middle])
{
right = middle - 1;
}
else if (target > elements[middle])
{
left = middle + 1;
}
else {
return middle;
}
}
return -1;
}```

2

Which sort contains a recursive call?

3

Under what condition will an ascending insertion sort execute the slowest?

2