Verityprep
Question Bank · Unit 4

AP® Computer Science A Data Collections Multiple Choice Questions

Work through AP Computer Science A multiple-choice questions on Data Collections, then check each answer against a worked solution.

Free · no sign-up Open questions need no account. Sign up or log in to open the rest.

Subtopic: Sorting And Searching Clear filter

Questions 121–130 of 139
  1. 121
  2. 122
  3. 123
  4. 124
  5. 125
  6. 126
  7. 127
  8. 128
  9. 129
  10. 130

Question 121

Multiple choice Sorting And Searching
Which of the following is (are) true? I. Insertion sort takes longer when the array is sorted in ascending order and you want it sorted in…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 122

Multiple choice Sorting And Searching
Consider the following array: {7, 3, 8, 5, 2} Which of the following correctly…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 123

Multiple choice Sorting And Searching
The following incomplete method is intended to sort the array elem in ascending order using the selection sort algorithm. public static void sort(int[] elem) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 124

Multiple choice Sorting And Searching
The following method should sort the contents of the array in ascending order using insertion sort. Which of the following should replace /* missing code */ to…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 125

Multiple choice Sorting And Searching
The following method is a correct implementation of the selection sort algorithm. The method sorts the elements of arr so that they are in order from least to…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 126

Multiple choice Sorting And Searching
The following method performs binary search and returns the number of comparisons made. What does bSearch(arr, 23) return? public static int bSearch(int[] arr,…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 127

Multiple choice Sorting And Searching
Selection sort finds the minimum element and swaps it to the front. After exactly 2 complete passes of selection sort on the following array, what is the array?…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 128

Multiple choice Sorting And Searching

After exactly 2 passes of this partial insertion sort, what is the array?

int[] arr = {8, 3, 5, 1, 4};
for (int i = 1; i < 3; i++) {
    int key = arr[i];
    int j = i - 1;
    while (j >= 0 && arr[j] > key) {
        arr[j + 1] = arr[j];
        j--;
    }
    arr[j + 1] = key;
}
Pick an answer, then check it. The solution opens in a window.

Question 129

Multiple choice Sorting And Searching
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,…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 130

Multiple choice Sorting And Searching
Consider the following code segment, which performs a binary search.
int[] a = { 2, 5, 8, 11, 14, 17, 20, 23, 26, 29 };
int target = 20;
int low = 0;
int high = a.length - 1;
int steps = 0;
int foundIdx = -1;
while (low <= high && foundIdx == -1)
{
    int mid = (low + high) / 2;
    steps++;
    if (a[mid] == target)
    {
        foundIdx = mid;
    }
    else if (a[mid] < target)
    {
        low = mid + 1;
    }
    else
    {
        high = mid - 1;
    }
}
System.out.println(steps);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.
Question 121 of 139
Page 13 of 14