Before the main algorithm runs, the program must be sure that the data it receives satisfies the constraints set by the problem. Without validation the program may:
Crash (division by zero, array‑index out of bounds).
Produce mathematically incorrect results (overflow, underflow).
Accept malicious data (e.g., injection attacks – relevant for Paper 2).
3.2 Types of Validation (Syllabus 7‑8)
Check
Description
Typical Exam Example
Type
Is the input an integer, real, character string, etc.?
Mark must be an INTEGER.
Range
Does the value lie between a lower and upper bound?
0 ≤ mark ≤ 100.
Format
Does the input follow a pattern (date, time, ISBN, email)?
DD/MM/YYYY.
Presence
Is a required field left empty?
Student name cannot be blank.
Check‑digit
Arithmetic rule that validates a code (ISBN, bar‑code, credit‑card).
ISBN‑10 check‑digit formula.
3.3 Validation Checklist (to write before coding)
List every input variable.
State its required type, range, format and any check‑digit rule.
Decide the error handling strategy:
Display a clear message (e.g., “Invalid mark – must be 0‑100”).
Terminate the algorithm or request a new input.
3.4 Example – ISBN‑10 Validation (Pseudo‑code)
READ isbn // expects 10 characters
IF LENGTH(isbn) ≠ 10 THEN
WRITE "ISBN must be 10 characters"
STOP
END IF
sum ← 0
FOR i ← 1 TO 9 DO
digit ← NUMERIC_VALUE(isbn[i]) // 0‑9
sum ← sum + i * digit
END FOR
check ← (11 - (sum MOD 11)) MOD 11
IF check = 10 THEN
expected ← 'X'
ELSE
expected ← CHAR(check + 48) // convert to character
END IF
IF isbn[10] = expected THEN
WRITE "ISBN is valid"
ELSE
WRITE "ISBN is invalid"
END IF
4. Verification – Checking the Algorithm’s Logic (AO2 + AO3)
4.1 What Verification Achieves
Verification confirms that, **given only valid inputs**, the algorithm always produces the correct output. It does not test the handling of bad data – that is the role of validation.
4.2 Verification Techniques
Step‑by‑step tracing – use a trace table (dry‑run) for a chosen test case.
Test‑data selection – at least one case from each category: Normal, Abnormal, Boundary, Extreme.
Visual checks – compare algorithm’s output with a hand‑calculated result or a diagram.
Double‑entry checks – run the same data twice (or with a partner) and compare results.
Mathematical proof or induction – useful for sorting, summation, or recurrence algorithms.
4.3 Test‑Data Categories (Syllabus 7‑8)
Category
Purpose
Typical Example (Mark 0‑100)
Normal
Typical value inside the range.
73
Abnormal
Correct type but outside the permitted range.
-5 or 120
Boundary
Exact limits of the range.
0 and 100
Extreme
Largest/smallest valid values that stress the algorithm (e.g., very large n for a loop).
n = 0, n = 1000 (if allowed)
4.4 Trace‑Table Example – Grading Algorithm
Step
mark
Condition Tested
grade
1
85
mark ≥ 80
A
2
73
mark ≥ 80 ? No → mark ≥ 70
B
3
66
… ≥ 60
C
4
52
… ≥ 50
D
5
38
None of the above
F
4.5 Common Pitfall – Off‑by‑One Error
total ← 0
FOR i ← 1 TO n‑1 DO // ❌ should be TO n
total ← total + i
END FOR
How to locate:
Create a trace table for a small n (e.g., 5).
Notice the loop stops at i = 4, giving total = 10 instead of 15.
Correct the bound to FOR i ← 1 TO n DO.
5. Full Example – From Validation to Verification
Problem Statement
Write a program that reads a student’s numeric mark (0‑100) and outputs the corresponding grade (A‑F). Include validation of the input and verify the algorithm with appropriate test data.
5.1 Validation (before any calculation)
// 1. Type check – assume READ returns an integer; if not, the exam will state “integer input”.
READ mark
IF mark < 0 OR mark > 100 THEN
WRITE "Error: mark must be between 0 and 100"
STOP
END IF
5.2 Main Algorithm (verification part)
IF mark ≥ 80 THEN
grade ← 'A'
ELSE IF mark ≥ 70 THEN
grade ← 'B'
ELSE IF mark ≥ 60 THEN
grade ← 'C'
ELSE IF mark ≥ 50 THEN
grade ← 'D'
ELSE
grade ← 'F'
END IF
WRITE "Grade:", grade
5.3 Test Data (AO3)
Normal: 73 → B
Boundary: 80 → A, 50 → D, 0 → F
Abnormal: -3 → error message, 105 → error message
Extreme: 100 → A (largest valid mark)
5.4 Trace Table (for normal case 73)
Line
mark
Test
grade
1
73
mark ≥ 80 ? No
2
73
mark ≥ 70 ? Yes
B
6. Practical Exam Tips (AO1‑AO3)
Plan first: write a brief validation checklist, then sketch a flowchart or outline pseudocode.
Include // validation and // main algorithm comments – they earn marks for clarity.
Choose at least four test cases covering all four categories; label them clearly in your answer.
Produce a full trace table for one normal case – show variable values after each step.
If you run out of time, add a simple “error message” validation; it is better than none.