← All Paper 2 problems·All lessons
Paper 2 scenario practice

Linear search of student IDs

The scenario
A school stores 100 student IDs in an array. The administrator wants a program that: 1. Has the 100 student IDs already loaded in an array called StudentIDs[1:100]. (You do NOT need to load them — assume they are present.) 2. INPUTS a target ID to search for. 3. Performs a LINEAR SEARCH through the array. 4. If the target is found, outputs the position (the array index where it was found). 5. If the target is NOT found, outputs a message saying so. Write a program in pseudocode (or a high-level language of your choice). Marks will be awarded for using a Found flag, terminating the search at the right moment, and clear program structure.
Lessons that prepare for this: Lesson 19 — Pseudocode and flowcharts · Lesson 21 — Searching algorithms · Lesson 24 — Arrays
Marking scheme — total 15 marks
Cambridge IGCSE 0478 Paper 2
  • 2
    Declare and initialise variables: DECLARE the target, position, and Found flag with sensible types. Initialise Found ← FALSE before the loop.
  • 1
    Read the target: INPUT the target ID before the search begins.
  • 4
    Loop through the array: Use a WHILE loop (or FOR with early termination) that visits each array position, comparing the element against the target. Stop when found OR when the array is exhausted.
  • 3
    Update flag and record position: When the target is found, set Found ← TRUE AND store the index in position. The loop must then end (do not continue searching after finding).
  • 3
    Output the result: After the loop, IF Found = TRUE THEN output 'Found at position', position. ELSE output a not-found message. Use a single IF/ELSE, not two separate IFs.
  • 2
    Program structure and naming: Code reads top-to-bottom; clear identifiers (target, position, Found — not t, p, f); WHILE/ENDWHILE properly paired; logic visible without comments needed.
Hints — reveal one at a time, only if stuck
Your pseudocode workspace
1 line