0:00

Which of the following correctly shows the iterations of an ascending (from left to right) insertion sort on an array with the following elements: {7,3,8,5,2}?

1

What is printed when the following main method is executed?

public class Searcher
{
private int[] arr = {1,3,5,8,9};

public int mystery(int low, int high, int num)
{
int mid = (low + high) / 2;
if (low > high) {
return -1;   }
else if (arr[mid] < num) {
return mystery(mid + 1, high, num);   }
else if (arr[mid] > num) {
return mystery(low, mid - 1, num);   }
else
return mid;
}

public static void main(String[] args)
{
Searcher s = new Searcher();
System.out.println(s.mystery(0,4,3));
}
}

3

Which of the following correctly shows the iterations of an ascending (from left to right) selection sort on an array with the following elements: {10, 6, 3, 2, 8}?

4

Which of the following could be used to replace /* missing code */ in the code so that the method always sorts the array elem in ascending order?

public class Searcher
{

public static void sort(int[] elem)
{
for (int j = 0; j < elem.length - 1; j++)
{
int minIndex = j;

for (/* missing code */)
{
if (elem [k] < elem [minIndex])
{
minIndex = k;
}
}
int temp = elem[j];
elem[j] = elem[minIndex];
elem[minIndex] = temp;
}
}

public static void main(String[] args)
{
int[] nums = {28, -3, 2, 14, 30};
Searcher.sort(nums);
}
}

2