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.
Multiple choice
2D Arrays
Question 1032
Multiple choice
Arraylists
Question 1033
Multiple choice
2D Arrays
Consider the following method.
public static int f(int n)
{
if (n <= 1)
{
return n;
}
return n + f(n - 2);
}
What is returned by the call f(7)?
Pick an answer, then check it. The solution opens in a window.
BCorrect answer
Main Solution
Answer
Answer: B. The call unwinds as f(7) = 7 + f(5) = 7 + 5 + f(3) = 7 + 5 + 3 + f(1). Since 1 <= 1, f(1) = 1. Total = 7 + 5 + 3 + 1 = 16.
Answer: Correct: B
Answer images
Question 1034
Multiple choice
2D Arrays
Question 1035
Multiple choice
2D Arrays
Question 1036
Multiple choice
Recursion
Question 1037
Multiple choice
Sorting And Searching
Question 1038
Multiple choice
Sorting And Searching
Consider using insertion sort (processing index
i from 1 upward, inserting arr[i] into the sorted prefix arr[0..i-1]) on the array {8, 2, 6, 1, 4}.
What is the array after the first three iterations (i = 1, 2, 3) of the outer loop?
Pick an answer, then check it. The solution opens in a window.
BCorrect answer
Main Solution
Answer
Answer: B. Insertion sort builds a sorted prefix one element at a time. Starting from{8, 2, 6, 1, 4}:i = 1: insert
2 into {8} → {2, 8, 6, 1, 4}.i = 2: insert
6 into {2, 8} → {2, 6, 8, 1, 4}.i = 3: insert
1 into {2, 6, 8} → {1, 2, 6, 8, 4}.Option A stops after two iterations; option C is the final fully sorted result after all iterations.
Answer: Correct: B
A
{2, 6, 8, 1, 4}
B
{1, 2, 6, 8, 4}
C
{1, 2, 4, 6, 8}
D
{2, 1, 6, 8, 4}
Answer images
Question 1039
Multiple choice
Arrays
Question 1040
Multiple choice
Using Text Files
Question 1,031 of 1,079
Page 104 of 108
AP® and Advanced Placement® are registered trademarks of the College Board, which is not affiliated with, and does not endorse, Verityprep. Names are used for identification purposes only.

