---
title: "AP CSA 2.12: Informal Run-Time Analysis"
description: "Review AP Computer Science A 2.12, including informal code analysis, statement execution counts, loop iteration counts, single loops, nested loops, triangular loop counts, tracing iterative statements, and informal run-time comparison."
canonical: "https://fiveable.me/ap-comp-sci-a/unit-2/informal-code-analysis/study-guide/CR84MbOE4FDDoSVokDVZ"
type: "study-guide"
subject: "AP Computer Science A"
unit: "Unit 2 – Selection and Iteration"
lastUpdated: "2026-06-07"
---

# AP CSA 2.12: Informal Run-Time Analysis

## Summary

Review AP Computer Science A 2.12, including informal code analysis, statement execution counts, loop iteration counts, single loops, nested loops, triangular loop counts, tracing iterative statements, and informal run-time comparison.

## Guide

## TLDR
Informal run-time analysis in [AP Computer Science A](/ap-comp-sci-a "fv-autolink") means counting how many times statements run, especially inside loops, by [tracing](/ap-comp-sci-a/key-terms/tracing "fv-autolink") through the code. You figure out a statement execution count, then compare iterative statements to see which one does more work as the input grows. This is mostly a tracing-and-counting skill, not memorizing formal Big O rules.

## Why This Matters for the AP Computer Science A Exam

This topic builds the habit of describing what a code segment actually does, step by step. On the multiple-choice section, you may be asked to determine the result of a code segment or how many times a statement runs for given input, and careful counting of [loop](/ap-comp-sci-a/key-terms/loop "fv-autolink") iterations is exactly what those questions test. The same tracing skill helps you check your own loops when you write free-response code, since you can confirm a loop runs the right number of times instead of one too many or one too few.

Run-time comparison here is informal. You are counting executions and comparing iterative statements, not proving formal complexity. Keep your reasoning grounded in tracing.

## Key Takeaways

- A statement execution count is the number of times a statement runs during a program. You usually find it by tracing the loops.
- A single loop over n items runs its body about n times, so the count grows in step with the input size.
- [Nested loops](/ap-comp-sci-a/key-terms/nested-loops "fv-autolink") multiply: if both loops depend on n, the inner statement can run on the order of n times n.
- Triangular nested loops, where the [inner loop](/ap-comp-sci-a/key-terms/inner-loop "fv-autolink") bound depends on the outer [variable](/ap-comp-sci-a/unit-1/expressions-and-assignment-statements/study-guide/01dr6uUPDAn3SjtK2Psr "fv-autolink"), run 1 + 2 + 3 + ... which totals n(n+1)/2.
- Operations outside any loop run a fixed number of times no matter how big the input is.
- Trace with a small sample input and an actual count when you are unsure. Counting beats guessing.

## How to Count Statement Executions

Start by asking: how many times does this exact line run? Use a trace [table](/ap-comp-sci-a/unit-4/introduction-to-using-data-sets/study-guide/fq4I4p0XINBBV56xQfTx "fv-autolink") or a small value of n and count.

### Single Loops

A single loop that visits each element once runs its body once per element.

```java
// Body runs array.length times
public int findMax(int[] array) {
    int max = array[0];
    for (int i = 1; i < array.length; i++) {  // runs array.length - 1 times
        if (array[i] > max) {
            max = array[i];
        }
    }
    return max;
}
```

If the [array](/ap-comp-sci-a/unit-4/array-creation-and-access/study-guide/umTe6NA38OqZOhMZjFWi "fv-autolink") has n elements, the [loop body](/ap-comp-sci-a/key-terms/loop-body "fv-autolink") runs n - 1 times. The count grows directly with n.

### Nested Loops

When one loop sits inside another, multiply the [iteration](/ap-comp-sci-a/unit-2/while-loops/study-guide/7qGsGOh1UKALAWpJhZOi "fv-autolink") counts.

```java
// Inner statement runs n * n times
public void printAllPairs(int[] array) {
    for (int i = 0; i < array.length; i++) {      // n iterations
        for (int j = 0; j < array.length; j++) {  // n iterations each
            System.out.println(array[i] + ", " + array[j]);
        }
    }
}
```

With n elements, the inner print runs n times n times, so the execution count grows much faster than a single loop.

### Triangular (Dependent) Nested Loops

Not every nested loop runs the full n times on the inside. Watch the inner loop's [bounds](/ap-comp-sci-a/key-terms/bounds "fv-autolink").

```java
public int countPairs(int[] array) {
    int count = 0;
    for (int i = 0; i < array.length; i++) {
        for (int j = i; j < array.length; j++) {  // runs n, then n-1, then n-2 ...
            count++;
        }
    }
    return count;
}
```

The inner loop runs n times, then n - 1, then n - 2, and so on. Adding those gives n(n+1)/2 total inner executions. That still grows quickly, but it is about half of n times n, so counting carefully matters.

### Sequential Loops

Loops that run one after another add their counts. They do not multiply.

```java
public void processArray(int[] array) {
    for (int i = 0; i < array.length; i++) {  // n executions
        array[i] *= 2;
    }
    for (int i = 0; i < array.length; i++) {  // n more executions
        System.out.println(array[i]);
    }
}
```

The total body executions here are about n + n, not n times n. Side by side means add; nested means multiply.

## Comparing Iterative Statements

Informal comparison means lining up two pieces of code and asking which one runs its inner statement more times as the input grows.

```java
// Loop A: single pass
for (int i = 0; i < n; i++) {
    System.out.println(i);          // runs n times
}

// Loop B: nested pass
for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
        System.out.println(i + j);  // runs n * n times
    }
}
```

For a small n the two might feel similar, but as n grows, Loop B's inner statement count pulls far ahead. That gap is the whole point of an informal run-time comparison: you are predicting which code does more work without timing it on a computer.

## How to Use This on the AP Computer Science A Exam

### Code Tracing

When a question asks how many times a statement runs, trace it with a concrete value of n.

- Write down the loop control variable's value on each pass.
- Mark when the [Boolean](/ap-comp-sci-a/unit-1/variables-and-primitive-data-types/study-guide/rezA6f3hJz84TKaY5Jjl "fv-autolink") condition becomes false, since that controls when the loop stops.
- For nested loops, finish the inner loop completely before the [outer loop](/ap-comp-sci-a/key-terms/outer-loop "fv-autolink") advances.

### Counting Checklist

- Find the most-repeated statement, usually the innermost loop body.
- Count how many times each loop runs, then multiply nested loops and add sequential loops.
- Check the inner loop's bounds. A bound like `j = i` or `j < i` means a triangular count, not a full n by n.
- Verify the start and end values to avoid an off-by-one count.

### Common Trap

A loop header like `for (int i = 1; i <= n; i++)` runs n times, but `for (int i = 0; i < n; i++)` also runs n times. The difference is the starting value and the [comparison operator](/ap-comp-sci-a/key-terms/comparison-operator "fv-autolink"). Trace the boundaries instead of assuming, because being off by one changes your execution count.

## Common Misconceptions

- Every nested loop is not automatically n times n. If the inner loop bound depends on the outer variable, the count can be n(n+1)/2 or smaller. Read the bounds before deciding.
- Sequential loops do not multiply. Two loops one after another add their counts; only nested loops multiply.
- A statement execution count is a real number you can calculate by tracing, not a vague label. For this topic, count the executions rather than reaching for formal Big O notation.
- The loop body does not always run at least once. If the Boolean condition is false at the start, a `while` or `for` loop body runs zero times.
- More lines of code does not mean a higher execution count. A single statement inside a deeply nested loop can run far more often than many statements that sit outside loops.

## Related AP Computer Science A Guides

- [2.1 Algorithms with Selection and Repetition](/ap-comp-sci-a/unit-2/algorithms-with-selection-and-repetition/study-guide/42crNSZyW8IRsntk9IHe)
- [2.7 While Loops](/ap-comp-sci-a/unit-2/while-loops/study-guide/7qGsGOh1UKALAWpJhZOi)
- [2.6 Equivalent Boolean Expressions](/ap-comp-sci-a/unit-2/equivalent-boolean-expressions/study-guide/aMDnyFuOcAXnZigLW1vL)
- [2.11 Nested Iteration](/ap-comp-sci-a/unit-2/nested-iteration/study-guide/Buapg1KURHNbw6yRY8EZ)
- [2.8 For Loops](/ap-comp-sci-a/unit-2/for-loops/study-guide/DJuLxKz6SiSAX2cEVmCt)
- [2.10 Developing Algorithms Using Strings](/ap-comp-sci-a/unit-2/developing-algorithms-using-strings/study-guide/hDOL1VhnMQFPkBf6xMMW)

## Vocabulary

- **iteration statement**: A control structure that repeats a block of code multiple times based on a condition.
- **run-time**: The period during which a program is executing or running.
- **statement execution count**: The number of times a statement is executed during the running of a program.
- **tracing**: The process of manually following the execution of a program step-by-step to understand how statements are executed.

## FAQs

### What is informal run-time analysis in AP CSA?

Informal run-time analysis means counting how many times statements execute, especially inside loops. AP CSA uses this as a tracing skill, so you compare iterative statements by reasoning through how often key lines run.

### What is a statement execution count?

A statement execution count is the number of times a specific statement runs during a program. You usually find it by tracing loop variables and counting each time the statement is reached.

### How do you count executions in a single loop?

For a single loop, identify the starting value, stopping condition, and update. If a loop visits every element in an array once, its body usually runs array.length times or array.length minus 1 times, depending on the starting index.

### How do nested loops affect execution counts?

Nested loops often multiply execution counts. If an outer loop runs n times and the inner loop runs n times for each outer pass, a statement inside the inner loop runs n times n times.

### What is a triangular loop count?

A triangular loop count happens when the inner loop depends on the outer loop variable, such as running n times, then n - 1 times, then n - 2 times. The total is often 1 + 2 + 3 + ... + n, or n(n + 1) / 2.

### What is a common AP CSA mistake with run-time analysis?

A common mistake is assuming every nested loop runs n squared times. Check the inner loop bounds first, because dependent loops, early starts, and different stopping conditions can change the exact count.

## Structured Data

```json
{"@context":"https://schema.org","@type":"FAQPage","inLanguage":"en","mainEntity":[{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-2/informal-code-analysis/study-guide/CR84MbOE4FDDoSVokDVZ#what-is-informal-run-time-analysis-in-ap-csa","name":"What is informal run-time analysis in AP CSA?","acceptedAnswer":{"@type":"Answer","text":"Informal run-time analysis means counting how many times statements execute, especially inside loops. AP CSA uses this as a tracing skill, so you compare iterative statements by reasoning through how often key lines run."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-2/informal-code-analysis/study-guide/CR84MbOE4FDDoSVokDVZ#what-is-a-statement-execution-count","name":"What is a statement execution count?","acceptedAnswer":{"@type":"Answer","text":"A statement execution count is the number of times a specific statement runs during a program. You usually find it by tracing loop variables and counting each time the statement is reached."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-2/informal-code-analysis/study-guide/CR84MbOE4FDDoSVokDVZ#how-do-you-count-executions-in-a-single-loop","name":"How do you count executions in a single loop?","acceptedAnswer":{"@type":"Answer","text":"For a single loop, identify the starting value, stopping condition, and update. If a loop visits every element in an array once, its body usually runs array.length times or array.length minus 1 times, depending on the starting index."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-2/informal-code-analysis/study-guide/CR84MbOE4FDDoSVokDVZ#how-do-nested-loops-affect-execution-counts","name":"How do nested loops affect execution counts?","acceptedAnswer":{"@type":"Answer","text":"Nested loops often multiply execution counts. If an outer loop runs n times and the inner loop runs n times for each outer pass, a statement inside the inner loop runs n times n times."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-2/informal-code-analysis/study-guide/CR84MbOE4FDDoSVokDVZ#what-is-a-triangular-loop-count","name":"What is a triangular loop count?","acceptedAnswer":{"@type":"Answer","text":"A triangular loop count happens when the inner loop depends on the outer loop variable, such as running n times, then n - 1 times, then n - 2 times. The total is often 1 + 2 + 3 + ... + n, or n(n + 1) / 2."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-a/unit-2/informal-code-analysis/study-guide/CR84MbOE4FDDoSVokDVZ#what-is-a-common-ap-csa-mistake-with-run-time-analysis","name":"What is a common AP CSA mistake with run-time analysis?","acceptedAnswer":{"@type":"Answer","text":"A common mistake is assuming every nested loop runs n squared times. Check the inner loop bounds first, because dependent loops, early starts, and different stopping conditions can change the exact count."}}]}
```
