2015 Collegeboard Multiple Choice Review
Test Corrections
- Question 5
- Question 9
- Question 14
- Question 19
- Question 22
- Question 25
- Question 29
- Question 31
- Question 32
- Question 34
- Question 35
- Question 37
Question 5
Answer is A because for the expression to evaluate to true, the expressions on either side of the && operator must be true. If x is true then x || y is true regardless of the value of y, meaning (x || y) && x evaluates to true. If x is false, the expression evaluates to false regardless of the value of (x || y).
Question 9
Answer is E because the call Math.random() will produce a double between 0 and 1, not including 1. To generate a random number in the range of 1 to 6, the call Math.random() needs to be multiplied by the number of integers you want to generate, in this case 6, giving us Math.random() 6. Since each roll is independent, to simulate rolling two number cubes, we need to use this expression twice which simplifies to 2 + (int)(Math.random() 6) + (int)(Math.random() * 6).
Question 19
The answer is E because in condition I, the while loop will not execute, since 1, the value of x, is not less than 0, so nothing will be printed. In condition II, the while loop will execute one time, since 1, the value of x is less than or equal to 1, however, 1 is not even, so nothing will be printed. The value of x will then be incremented to 3, which is not less than or equal to 1, and the loop will terminate. In condition III, the while loop will execute for x having the value 1, 3, 5, 7, and 9. When x becomes 11 the loop will terminate. Even though the loop executes multiple times, the values assigned to x are not even, so nothing is printed.
Question 22
The answer is A because the outer for loop iterates over every row of numbers and assigns each row to the array row. The inner loop iterates over the array row accessing each element and assigning it to n. Then n is printed to the screen. In the first iteration of the outer loop, row is equal to {1, 2, 3}, and the inner loop will assign each successive value in row to n and print it to the screen, meaning 123 will be printed. For the second iteration of the outer loop, row is equal to {4, 5, 6}, and the inner loop will assign each successive value in row to n and print it to the screen, meaning 456 will be printed after 123, giving us the output 123456.
Question 25
The answer is C because the outer loop iterates four times (for x = 0, 1, 2, 3). When x is assigned 4, the loop terminates. The inner loop will iterate from the value of x to 4, not including 4. In the first iteration of the outer loop, the inner loop iterates four times (for y = 0, 1, 2, 3) and count will increase by 1 each time and will equal to 4. In the second iteration of the outer loop, the inner loop iterates three times (for y = 1, 2, 3) and count will now be 7. In the third iteration of the outer loop, the inner loop iterates two times (for y = 2, 3) and count will now be 9. In the fourth and final iteration of the outer loop, the inner loop will iterate one time (for y = 3) and count will be 10.
Question 29
The answer is A because each recursive call is made with the value num / 10. The expression num / 10 uses integer division and evaluates to an integer that is num with the right most digit removed. For example, 258 / 10 = 25. Each time the recursive call is made, what is returned is 1 plus the result of the recursive call. For example, what(258) = 1 + what(25) and what(25) = 1 + what(2) and what(2) = 1. Therefore what(258) = 1 + 1 + 1 or 3, which is the number of digits in 258.
Question 32
The answer is E because Choice I sets max to Integer.MIN_VALUE, which is the smallest possible integer value. Then it accesses each element in arr and assigns them value. If value is greater than max, max is assigned value since it is now the largest value so far. Choice II uses an if statement inside the for loop to check and see if value is the first element in arr or not. Once the first element is identified, max is initialized to the first element and first is set to false. For all subsequent elements in arr, if value is greater than max, max is assigned value since it is now the largest value so far. Choice III sets max to the first value in arr. Then it accesses each subsequent value in arr checking to see if the value is greater than max, if it is max is assigned this element since it is now the largest value so far.
Question 34
The answer is D because List is an interface, which an ArrayList implements. Please note that List is no longer tested as part of the AP CSA exam and ArrayList will be used instead. To determine the size of an ArrayList we need to call the method size(). Each word will be separated by a comma, but no comma should appear after the last element in the list. Therefore, a comma is added as long as k does not equal the last index, sizeOfList – 1, since list indices start at 0.
Question 35
The answer is C because in the first iteration of the binary search, it will check the value at index (0 + 7) / 2 which is index 3. Since 8 is greater than data[3], start is assigned mid + 1 which is 4 and the process will repeat. In the second iteration of the while loop, it will check the value at index (4 + 7) / 2 which is index 5. Since data[5] is 8, 5 is returned.
Question 37
The answer is E because Choice I iterates from startIndex to the end of the array words as expected, but when it adds elements to result it adds the current word followed by a second word starting at the end of the array words. This will result in duplicate words being added to result. Choice II starts at the end of the array words and adds each word to result working right to left until it reaches the startIndex. By starting at the end of the array, the elements are concatenated in reverse order. Choice III starts by adding the elements of words to temp in reverse order. The second loop starts at the beginning of temp (which was the end of words) and adds each subsequent element to result until it reaches the element that was at startIndex and is now at temp.length – startIndex resulting in result containing the required elements in reverse order.
Queue<String> queue = new LinkedList<>(); // Queue interface uses LL implementation
queue.add("John");
queue.add("Jane");
queue.add("Bob");
// Collections has a toArray convertion
Object[] arr = queue.toArray();
// Empty queue
System.out.println("Empty Queue");
while (queue.size() > 0) // Interate while size
System.out.println(queue.remove());
// Iterate of array
System.out.println("Iterate over Array");
for (Object a : arr) // Type is Object from convertion
System.out.println(a);