Coding Sheets, Practice & Learning Support: Common Exam Algorithm Patterns Summary Sheet (Copy)
Common Exam Algorithm Patterns Summary Sheet
Purpose Of This Sheet
- Ultra-condensed revision + recall sheet
- Covers most repeated algorithm structures seen in exams
- Designed to:
- Trigger recognition
- Speed up writing
- Reduce logic errors
- All patterns are copy-paste safe pseudocode
Pattern 1: Input → Process → Output (IPO)
Used When
- Single calculation
- Straightforward processing
INPUT value
result ← PROCESS(value)
OUTPUT result
Pattern 2: Fixed-Count Loop
Used When
- Number of inputs is known
FOR i ← 1 TO n
INPUT value
PROCESS value
NEXT i
Pattern 3: Counting Pattern
Used When
- “How many…”
- “Count the number of…”
count ← 0
FOR i ← 1 TO n
INPUT value
IF condition THEN
count ← count + 1
ENDIF
NEXT i
OUTPUT count
Pattern 4: Accumulation Pattern
Used When
- “Find the total…”
- “Calculate sum…”
total ← 0
FOR i ← 1 TO n
INPUT value
total ← total + value
NEXT i
OUTPUT total
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 AS Level Computer Science Full Scale Course
Pattern 5: Average Calculation
All Values Included
total ← 0
FOR i ← 1 TO n
INPUT value
total ← total + value
NEXT i
average ← total / n
OUTPUT average
Selected Values Only
total ← 0
count ← 0
FOR i ← 1 TO n
INPUT value
IF condition THEN
total ← total + value
count ← count + 1
ENDIF
NEXT i
IF count > 0 THEN
average ← total / count
OUTPUT average
ENDIF
Pattern 6: Maximum / Minimum
Exam-Safe Version
INPUT value
max ← value
min ← value
FOR i ← 2 TO n
INPUT value
IF value > max THEN
max ← value
ENDIF
IF value < min THEN
min ← value
ENDIF
NEXT i
OUTPUT max
OUTPUT min
Pattern 7: Validation (REPEAT UNTIL)
Range Check
REPEAT
INPUT value
UNTIL value >= min AND value <= max
Option Validation
REPEAT
INPUT option
UNTIL option = 1 OR option = 2 OR option = 3
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 AS Level Computer Science Full Scale Course
Pattern 8: Sentinel-Controlled Input
REPEAT UNTIL Sentinel
REPEAT
INPUT value
IF value <> sentinel THEN
PROCESS value
ENDIF
UNTIL value = sentinel
WHILE Sentinel
INPUT value
WHILE value <> sentinel DO
PROCESS value
INPUT value
ENDWHILE
Pattern 9: Flag Variable (Detection)
flag ← FALSE
FOR i ← 1 TO n
IF condition THEN
flag ← TRUE
ENDIF
NEXT i
IF flag = TRUE THEN
OUTPUT "Yes"
ELSE
OUTPUT "No"
ENDIF
Pattern 10: Early Exit Using Flag
flag ← FALSE
i ← 1
WHILE i <= n AND flag = FALSE DO
IF condition THEN
flag ← TRUE
ELSE
i ← i + 1
ENDIF
ENDWHILE
Pattern 11: Linear Search
found ← FALSE
i ← 1
WHILE i <= n AND found = FALSE DO
IF arr[i] = target THEN
found ← TRUE
ELSE
i ← i + 1
ENDIF
ENDWHILE
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 AS Level Computer Science Full Scale Course
Pattern 12: Bubble Sort (Ascending)
FOR pass ← 1 TO n - 1
FOR j ← 1 TO n - pass
IF arr[j] > arr[j + 1] THEN
temp ← arr[j]
arr[j] ← arr[j + 1]
arr[j + 1] ← temp
ENDIF
NEXT j
NEXT pass
Pattern 13: Nested Loops (Tables / Grids)
FOR row ← 1 TO rows
FOR col ← 1 TO cols
PROCESS table[row][col]
NEXT col
NEXT row
Pattern 14: Combined High-Mark Pattern
(Max + Min + Total + Average)
INPUT value
max ← value
min ← value
total ← value
count ← 1
FOR i ← 2 TO n
INPUT value
IF value > max THEN
max ← value
ENDIF
IF value < min THEN
min ← value
ENDIF
total ← total + value
count ← count + 1
NEXT i
average ← total / count
OUTPUT max
OUTPUT min
OUTPUT average
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 AS Level Computer Science Full Scale Course
Pattern Recognition Table (Fast Recall)
| Question Phrase | Use This Pattern |
|---|---|
| “How many…” | Counting |
| “Total / sum” | Accumulation |
| “Average” | Accumulation + Counter |
| “Largest / smallest” | Max / Min |
| “Until -1” | Sentinel |
| “Check if exists” | Flag |
| “Search for” | Linear Search |
| “Sort values” | Bubble Sort |
| “Grid / table” | Nested Loops |
| “Input must be valid” | Validation |
Master Exam Skeleton (Safe Default)
initialise variables
REPEAT / FOR / WHILE
INPUT
IF condition THEN
PROCESS
ENDIF
END LOOP
FINAL CALCULATION
OUTPUT
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 AS Level Computer Science Full Scale Course
Ultra-High-Yield Reminders
- Initialise everything
- Validate before processing
- Flags detect, counters count
- Sentinels stop input, not data
- Simple structure = more marks
