Arrays, Records & Data Handling: Tracing Arrays Step-By-Step In Dry Runs (Copy)
Tracing Arrays Step-By-Step In Dry Runs (Cambridge Standard – O Level 2210 + IGCSE 0478)
Why Dry Runs With Arrays Decide Paper 2 Marks
- Cambridge Paper 2 frequently tests:
- “Trace the algorithm”
- “Show the output”
- “Complete the trace table”
- Arrays increase difficulty because:
- You are tracking multiple values
- Index variables control what value is accessed
- Updates can change future values
- A correct dry run proves:
- You understand traversal, selection, and updates
- A wrong dry run usually happens due to:
- Index confusion
- Off-by-one errors
- Misreading loop boundaries
- Forgetting that array values may change during execution
What Cambridge Means By A “Dry Run”
- A dry run is:
- Manually executing the algorithm line-by-line
- Using the given input values
- Recording variable changes and outputs
- For arrays, this includes:
- Which element is accessed each step
- Any updates applied to elements
- How totals, counters, flags change
The Cambridge Dry Run Mindset (Non-Negotiable)
- Do not “guess the result”
- Do not jump to the final answer
- Follow:
- Every iteration
- Every IF condition
- Every assignment
- Examiners award marks for:
- Correct intermediate values
- Correct final output
- Correct termination point
Step 1: Set Up A Clean Dry Run Layout (Before You Trace)
A. Identify The Array Declaration And Bounds
- Write down:
- Lower bound
- Upper bound
- Example:
- DECLARE marks[1:6]
- Bounds: 1 to 6
B. Copy The Given Array Values Exactly
- Create a simple table of index → value
Example:
| Index | marks[index] |
|---|---|
| 1 | 55 |
| 2 | 42 |
| 3 | 78 |
| 4 | 10 |
| 5 | 90 |
| 6 | 50 |
C. Identify Variables That Must Be Traced
- Typical trace variables:
- Index variable (i, index, pos)
- Accumulator (total)
- Counter (count)
- Flag (found)
- Current element (temp, marks[i])
D. Identify Outputs
- Underline all OUTPUT statements in the algorithm
- Outputs must be recorded in order
Step 2: The “Iteration Table” Method (Best For Arrays)
- For loops, make a trace table with:
- One row per iteration
Example columns:
- i
- marks[i]
- condition result
- total / count / max
- output (if any)
Step 3: Tracing A FOR Loop Traversal (Standard Pattern)
Typical Algorithm Pattern
- total ← 0
- FOR i ← 1 TO 6
- total ← total + marks[i]
- ENDFOR
- OUTPUT total
Dry Run Table
| i | marks[i] | total after update |
|---|---|---|
| 1 | 55 | 55 |
| 2 | 42 | 97 |
| 3 | 78 | 175 |
| 4 | 10 | 185 |
| 5 | 90 | 275 |
| 6 | 50 | 325 |
- Output:
- total = 325
Examiner Trap
- Forgetting FOR loops are inclusive
- Stopping at i = 5 instead of i = 6
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Step 4: Tracing Arrays With IF Inside A Loop (Conditional Processing)
Algorithm Pattern
- passCount ← 0
- FOR i ← 1 TO 6
- IF marks[i] >= 50 THEN
- passCount ← passCount + 1
- ENDIF
- IF marks[i] >= 50 THEN
- ENDFOR
- OUTPUT passCount
Dry Run Table
| i | marks[i] | marks[i] >= 50 | passCount |
|---|---|---|---|
| 1 | 55 | TRUE | 1 |
| 2 | 42 | FALSE | 1 |
| 3 | 78 | TRUE | 2 |
| 4 | 10 | FALSE | 2 |
| 5 | 90 | TRUE | 3 |
| 6 | 50 | TRUE | 4 |
- Output:
- passCount = 4
Examiner Traps
- Updating passCount even when condition is FALSE
- Forgetting boundary value counts (50 is included)
Step 5: Tracing Maximum/Minimum With Arrays
Maximum Algorithm Pattern
- max ← marks[1]
- FOR i ← 2 TO 6
- IF marks[i] > max THEN
- max ← marks[i]
- ENDIF
- IF marks[i] > max THEN
- ENDFOR
- OUTPUT max
Dry Run Table
| i | marks[i] | max before | marks[i] > max | max after |
|---|---|---|---|---|
| 2 | 42 | 55 | FALSE | 55 |
| 3 | 78 | 55 | TRUE | 78 |
| 4 | 10 | 78 | FALSE | 78 |
| 5 | 90 | 78 | TRUE | 90 |
| 6 | 50 | 90 | FALSE | 90 |
- Output:
- max = 90
Examiner Trap
- Starting loop from i = 1 causes redundant comparison
- Starting from i = 3 skips an element
Step 6: Tracing WHILE Loops With Arrays (Search Patterns)
Linear Search Pattern
- found ← FALSE
- index ← 1
- WHILE found = FALSE AND index <= 6 DO
- IF marks[index] = target THEN
- found ← TRUE
- ELSE
- index ← index + 1
- ENDIF
- IF marks[index] = target THEN
- ENDWHILE
- OUTPUT found
Dry Run Example (target = 10)
| index | marks[index] | found before | marks[index] = 10 | found after | index after |
|---|---|---|---|---|---|
| 1 | 55 | FALSE | FALSE | FALSE | 2 |
| 2 | 42 | FALSE | FALSE | FALSE | 3 |
| 3 | 78 | FALSE | FALSE | FALSE | 4 |
| 4 | 10 | FALSE | TRUE | TRUE | 4 |
- Loop stops because found = TRUE
- Output:
- found = TRUE
Examiner Traps
- Incrementing index after finding target (should not happen in this structure)
- Forgetting boundary condition index <= 6
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Step 7: Tracing When The Array Is Updated During The Loop (Critical)
Algorithm Pattern (In-Place Update)
- FOR i ← 1 TO 6
- IF marks[i] < 50 THEN
- marks[i] ← 50
- ENDIF
- IF marks[i] < 50 THEN
- ENDFOR
- OUTPUT marks[2], marks[4]
Dry Run (Using The Same marks Array)
Original:
- [55, 42, 78, 10, 90, 50]
Update each iteration:
- i = 1: 55 stays
- i = 2: 42 becomes 50
- i = 3: 78 stays
- i = 4: 10 becomes 50
- i = 5: 90 stays
- i = 6: 50 stays
New array:
- [55, 50, 78, 50, 90, 50]
Output:
- marks[2] = 50
- marks[4] = 50
Examiner Trap
- Using original array values after they were updated
- In a dry run:
- Once updated, the new value is used from that point onwards
Step 8: Tracing Partial Traversals (Subranges)
Algorithm Pattern
- total ← 0
- FOR i ← 2 TO 5
- total ← total + marks[i]
- ENDFOR
- OUTPUT total
Dry Run Using marks Array (After update or original, depending on question)
If using original:
- marks[2]=42, marks[3]=78, marks[4]=10, marks[5]=90
- total = 42+78+10+90 = 220
Examiner Traps
- Including marks[1] by mistake
- Stopping at marks[4] and missing marks[5]
- Forgetting inclusive end bound
Written and Compiled By Sir Hunain Zia (AYLOTI), World Record Holder With 154 Total A Grades, 7 Distinctions and 11 World Records For Educate A Change O Level And IGCSE Computer Science Full Scale Course
Step 9: How To Record OUTPUT In Dry Runs (Order Matters)
- Write outputs in sequence as they appear
- If output occurs inside a loop:
- You may have multiple outputs
Example
- FOR i ← 1 TO 3
- OUTPUT marks[i]
- ENDFOR
Output list:
- marks[1]
- marks[2]
- marks[3]
Examiner Trap
- Writing only the final output when multiple outputs exist
Step 10: The Dry Run Error Checklist (Use This Before Final Answer)
- Did you write the correct array bounds?
- Did you start and end the loop correctly?
- Did you update variables only when conditions were TRUE?
- Did you treat updated array values as permanent from that point?
- Did you stop a WHILE search at the correct time?
- Did you record outputs in the correct order?
- Did you include boundary cases correctly (>=, <=, inclusive bounds)?
Common Dry Run Mistakes Cambridge Punishes
- Off-by-one indexing
- Forgetting initial values of counters/accumulators
- Treating FOR end as exclusive
- Updating counters when condition is false
- Continuing a search after found = TRUE
- Recording outputs incorrectly
- Using original array values after an update
Best-Practice Dry Run Strategy For Paper 2
- Always start by rewriting array with indices
- Use a structured table (not mental maths)
- Track:
- index
- current element
- key variables
- Mark each IF as TRUE or FALSE explicitly
- Record each output at the moment it happens
- After the loop ends, do a quick reasonableness check
Final Quality Checklist
- Array values copied correctly
- Indices labelled correctly
- Loop boundaries correct
- Variable updates correct
- Outputs recorded correctly
- Updated array values carried forward correctly
Final Lock-In Rules
- Dry runs are step-by-step execution, not guessing
- Arrays require correct index tracking
- Updates change future values
- Output order matters
- Clean tracing earns easy Paper 2 marks
