AP Computer Science A Practice Quiz: Informal Run-Time Analysis
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 7 questions to check your progress.
Question 1 of 7
All Questions (7)
A) The number of times a specific statement is executed by the program.
B) The total memory in bytes used by the program.
C) The time in seconds it takes for a program to run.
D) The number of variables declared in a program.
Correct Answer: A
This is a direct definition from the provided content: 'A statement execution count indicates the number of times a statement is executed by the program.'
A) 0
B) 1
C) 15
D) 16
Correct Answer: C
The `for` loop is an iterative statement. It initializes `i` at 0 and continues as long as `i` is less than 15. The loop will run for i = 0, 1, 2, ..., 14, which is a total of 15 times. Therefore, the statement inside the loop is executed 15 times.
A) 8
B) 16
C) 64
D) 72
Correct Answer: C
The outer loop runs `n` times (8 times). For each single iteration of the outer loop, the inner loop runs `n` times (8 times). Therefore, the statement `count++;` is executed n * n times, which is 8 * 8 = 64 times.
A) The execution count in Snippet A is significantly higher than in Snippet B.
B) The execution count in Snippet B is significantly higher than in Snippet A.
C) The execution counts are approximately the same for both snippets.
D) The comparison cannot be made without knowing the exact value of `n`.
Correct Answer: B
In Snippet A, there are two sequential iterative statements. The first loop executes `work()` `n` times, and the second loop also executes it `n` times, for a total of `2n` executions. In Snippet B, the loops are nested. The inner loop executes `n` times for each of the `n` executions of the outer loop, for a total of `n*n` or `n^2` executions. For a large `n`, `n^2` is significantly larger than `2n`.
A) 5
B) 10
C) 49
D) 50
Correct Answer: B
The iterative statement initializes `i` to 0 and increments `i` by 5 in each iteration. The loop continues as long as `i < 50`. The values of `i` for which the loop body executes will be 0, 5, 10, 15, 20, 25, 30, 35, 40, and 45. The next value would be 50, which is not less than 50, so the loop terminates. This results in a total of 10 iterations, so the statement is executed 10 times.
A) By using a high-precision stopwatch to time the code.
B) By counting the lines of code in the program.
C) By compiling the code and measuring the size of the executable file.
D) By tracing and analyzing the iterative statements.
Correct Answer: D
The provided content states that 'Statement execution counts are often calculated informally through tracing and analysis of the iterative statements.' This involves manually stepping through loops and other control structures to count executions.
A) 10
B) 15
C) 20
D) 25
Correct Answer: B
This requires careful tracing of the nested loops. The inner loop's starting point (`j=i`) depends on the outer loop's variable. - When i = 0, the inner loop runs for j = 0, 1, 2, 3, 4 (5 times). - When i = 1, the inner loop runs for j = 1, 2, 3, 4 (4 times). - When i = 2, the inner loop runs for j = 2, 3, 4 (3 times). - When i = 3, the inner loop runs for j = 3, 4 (2 times). - When i = 4, the inner loop runs for j = 4 (1 time). The total execution count is 5 + 4 + 3 + 2 + 1 = 15.