PrepGo

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

According to the principles of informal run-time analysis, what does a "statement execution count" measure?

All Questions (7)

According to the principles of informal run-time analysis, what does a "statement execution count" measure?

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.'

Consider the following code snippet. How many times will the statement `System.out.println("*");` be executed? ```java int n = 15; for (int i = 0; i < n; i++) { System.out.println("*"); // This statement } ```

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.

Analyze the following code segment. What is the statement execution count for `count++;`? ```java int n = 8; int count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { count++; // This statement } } ```

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.

Which of the following provides the most accurate informal run-time comparison of the `work()` method calls in Snippet A and Snippet B, assuming `n` is a large positive integer? ```java // Snippet A for (int i = 0; i < n; i++) { work(); } for (int j = 0; j < n; j++) { work(); } // Snippet B for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { work(); } } ```

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`.

What is the statement execution count for `x++;` in the following code segment? ```java int n = 50; int x = 0; for (int i = 0; i < n; i = i + 5) { x++; // This statement } ```

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.

How is the statement execution count for a program segment typically determined in informal run-time analysis?

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.

By tracing the execution of the following code, determine the final value of `count`, which represents the execution count of the inner statement. ```java int n = 5; int count = 0; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { count++; } } ```

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.