Informal Run-Time Analysis FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

A sign printer uses this countdown:

int n = 10;
while (n > 0) {
    System.out.print("X");
    n--;
}

(a) State how many times print("X") executes. (b) State the new count if the condition is changed to n > 3. (c) List the n values that still run the body under n > 3.

Question 2 of 5

Complete the running execution counts for this loop.

int shown = 0;
for (int i = 0; i < 5; i++) {
    shown++;
    System.out.print(shown);
}
i during this pass Value of shown after shown++ Times print has executed after this pass
0
1
2
3
4

Question 3 of 5

Two nested fragments print a mark. Fragment R uses inner j <= 4. Fragment S uses inner j <= 3. Both use outer i from 1 through 4.

for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= 4; j++) {
        System.out.print("R");
    }
}
for (int i = 1; i <= 4; i++) {
    for (int j = 1; j <= 3; j++) {
        System.out.print("S");
    }
}

(a) State how many times print("R") executes and how many times print("S") executes. (b) State how many more times R prints than S. (c) Explain the difference as extra inner completions on each outer pass.

Question 4 of 5

A clerk needs two different loops that print a dash.

(a) Write a for loop that executes print("-") exactly 7 times using a +1 update. (b) Write a for loop that executes print("-") exactly 4 times by starting at 1, continuing while i <= 7, and adding 2 each time. (c) List the i values for the loop in (b) and explain why it runs fewer times than a +1 loop with the same bounds 1 through 7.

Question 5 of 5

Trace the two counters:

int a = 0;
int b = 0;
for (int i = 1; i <= 6; i++) {
    a++;
    for (int j = 1; j <= 2; j++) {
        b++;
    }
}

(a) State the final values of a and b. (b) State a + b. (c) Explain, by counting completed inner iterations, why b is not equal to a. (d) State the new value of b if the inner bound is changed to j <= 3, with the outer bound unchanged.