AP® Computer Science A Multiple Choice Questions
Work through AP Computer Science A multiple-choice questions unit by unit, 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
Unit 4: Data Collections
Question 2762
Multiple choice
Unit 4: Data Collections
Question 2763
Multiple choice
Unit 4: Data Collections
Question 2764
Multiple choice
Unit 4: Data Collections
Question 2765
Multiple choice
Unit 4: Data Collections
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 2766
Multiple choice
Unit 4: Data Collections
Question 2767
Multiple choice
Unit 4: Data Collections
Question 2768
Multiple choice
Unit 4: Data Collections
Question 2769
Multiple choice
Unit 4: Data Collections
Question 2770
Multiple choice
Unit 4: Data Collections
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 2,761 of 2,811
Page 277 of 282
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.

