2.12 Informal Run-Time Analysis
1. Exam Points
Nested loops (while, for)
Analyze how many times some statements are executed.
Analyze how many times a method is called.
Note:
- !
How a loop control variable changes. (++, --, +=2, +=3)
- Use specific values to represent m or n when necessary to simplify a situation.
- If an outer loop is never executed, neither does the inner loop.
2. Knowledge Points
(1) Informal Run-Time Analysis
- A statement execution count indicates
the number of times a statement is executed by the program.
- Statement execution counts are often calculated informally through tracing and analysis of the iterative statements.
- Example 1: the inner j does not change with the outer i.
- If the inner j does not change with the outer i, multiply the numbers of the outer loop and the inner loop.
- Example 2: the inner j changes with the outer i.
- If the inner j changes with the outer i, add the number of each outer iteration.
3. Exercises