The Problem Every Programmer Faces

You are given a task: build a program that accepts student marks, finds the highest score, and outputs the result. Where do you start? Do you jump straight to coding? Most students do, and most students lose marks for it. The IGCSE Computer Science syllabus expects you to show a structured approach to solving problems before writing a single line of code. That structured approach is what this topic is about.

Algorithm design and problem-solving sits at the heart of Paper 2 (0478). The examiners want to see that you can break a problem apart, design a solution using pseudocode or flowcharts, trace through your logic, and test it properly. Every skill in this topic connects to real exam questions, so precision matters.

The Program Development Life Cycle

Every program goes through four stages. The Cambridge IGCSE syllabus names them explicitly, and you should know what happens at each one.

StagePurposeKey Activities
AnalysisUnderstand the problemIdentify inputs, outputs, and processes. Define requirements clearly.
DesignPlan the solutionCreate flowcharts, write pseudocode, draw structure diagrams.
CodingBuild the programTranslate the design into a programming language.
TestingCheck it worksUse normal, abnormal, and boundary test data to verify correctness.

Analysis is where you ask: what are the inputs? What should the output be? What processing needs to happen? If the problem says "accept 10 numbers and output the average," your analysis identifies the inputs (10 numbers), the process (sum them, divide by 10), and the output (the average).

Design is where you represent your solution visually or in structured text. Coding turns that design into executable instructions. Testing confirms the program handles all expected and unexpected scenarios.

Decomposition and Structure Diagrams

Large problems are difficult to solve in one step. Decomposition means breaking a complex problem into smaller, manageable sub-problems. Each sub-problem can then be solved independently.

This approach is called top-down design (or stepwise refinement). You start with the main problem at the top and divide it into sub-tasks. Each sub-task can be divided further until every piece is simple enough to implement directly.

A structure diagram shows this hierarchy visually. The main task sits at the top, with branches leading down to sub-tasks, which branch further into smaller steps.

Example: a program to manage a class register might decompose like this:

  • Class Register System
    • Add Student (get name, get ID, store record)
    • Remove Student (search by ID, delete record)
    • Display All Students (loop through records, format output)

Each leaf node in the structure diagram is small enough to write as a short sequence of instructions. That is the goal of decomposition: reduce complexity until each piece is straightforward.

Algorithm Design Methods

Pseudocode

Pseudocode is a structured way of writing an algorithm using English-like statements. The Cambridge IGCSE syllabus uses a specific pseudocode syntax, and you should follow it closely in exams.

Key constructs in Cambridge pseudocode:

  • Assignment: Variable ← Value (written as Variable ← Value)
  • Input: INPUT Variable
  • Output: OUTPUT Variable
  • Selection: IF...THEN...ELSE...ENDIF
  • Counted loop: FOR...TO...NEXT
  • Pre-condition loop: WHILE...DO...ENDWHILE
  • Post-condition loop: REPEAT...UNTIL
Exam Tip: Cambridge examiners are strict about pseudocode syntax. Always use ENDIF, ENDWHILE, and NEXT to close your structures. Missing these closing keywords loses you marks.

Flowcharts

Flowcharts use standard symbols to represent an algorithm visually:

SymbolShapePurpose
Oval (rounded rectangle)Rounded endsStart or Stop
RectangleStraight edgesProcess (calculation, assignment)
ParallelogramSlanted sidesInput or Output
DiamondFour-sided pointDecision (Yes/No question)
ArrowDirected lineFlow direction

Flowcharts must have exactly one Start and one Stop terminal. Every decision diamond must have two labelled exits (typically "Yes" and "No"). Arrows must show the direction of flow clearly.

Trace Tables

A trace table tracks the value of every variable as you step through an algorithm line by line. Each row represents one step of execution. Trace tables are essential for finding logic errors and are commonly tested in the IGCSE exam.

The columns of a trace table correspond to: each variable in the algorithm, and optionally an OUTPUT column. You fill in a new row each time a variable changes or an output is produced.

Worked Example 1: Trace Table Walkthrough

Problem: Trace through the following pseudocode and determine the output.

Count ← 0
Total ← 0
FOR Index ← 1 TO 4
  INPUT Number
  IF Number > 0 THEN
    Total ← Total + Number
    Count ← Count + 1
  ENDIF
NEXT Index
OUTPUT Total, Count

Test data entered: 5, -3, 8, 0

Step through the algorithm with a trace table:

IndexNumberTotalCountOUTPUT
--00
1551
2-351
38132
40132
----13, 2

Analysis of each iteration:

  1. Index = 1: Number is 5. Since 5 > 0, Total becomes 0 + 5 = 5, Count becomes 0 + 1 = 1.
  2. Index = 2: Number is -3. Since -3 is NOT > 0, the IF block is skipped. Total stays at 5, Count stays at 1.
  3. Index = 3: Number is 8. Since 8 > 0, Total becomes 5 + 8 = 13, Count becomes 1 + 1 = 2.
  4. Index = 4: Number is 0. Since 0 is NOT > 0, the IF block is skipped. Total stays at 13, Count stays at 2.

Final output: 13, 2. The algorithm totals only the positive numbers and counts how many there are.

Standard Algorithms

The IGCSE syllabus requires you to know several standard algorithms. You need to be able to write them in pseudocode, trace through them, and explain how they work.

Linear Search

Linear search checks each element in a list one by one until it finds the target value or reaches the end.

Pseudocode:

Found ← FALSE
Index ← 0
WHILE Found = FALSE AND Index < Length
  IF List[Index] = Target THEN
    Found ← TRUE
  ELSE
    Index ← Index + 1
  ENDIF
ENDWHILE
IF Found = TRUE THEN
  OUTPUT "Found at position ", Index
ELSE
  OUTPUT "Not found"
ENDIF

Linear search works on unsorted data. Its weakness is speed: for a list of 1000 items, it might need up to 1000 comparisons in the worst case.

Bubble Sort

Bubble sort compares adjacent pairs and swaps them if they are in the wrong order. It repeats passes through the list until no swaps occur.

Pseudocode:

REPEAT
  Swapped ← FALSE
  FOR Index ← 0 TO Length - 2
    IF List[Index] > List[Index + 1] THEN
      Temp ← List[Index]
      List[Index] ← List[Index + 1]
      List[Index + 1] ← Temp
      Swapped ← TRUE
    ENDIF
  NEXT Index
UNTIL Swapped = FALSE

The three-line swap using a temporary variable is critical. You cannot simply write List[Index] ← List[Index + 1] first, because that overwrites the original value before you can move it. The temporary variable preserves it.

Totalling, Counting, and Finding Max/Min

These are fundamental patterns that appear in almost every algorithm question.

Totalling: Start with Total = 0, then add each value in a loop.

Counting: Start with Count = 0, then increment by 1 each time a condition is met.

Finding Maximum: Set Max to the first value, then compare each subsequent value. If a value is larger than Max, update Max.

Finding Minimum: Same logic, but check if the value is smaller.

Pseudocode for finding the maximum in a list:

Max ← List[0]
FOR Index ← 1 TO Length - 1
  IF List[Index] > Max THEN
    Max ← List[Index]
  ENDIF
NEXT Index
OUTPUT Max

Worked Example 2: Writing Pseudocode from a Problem Statement

Problem: A teacher wants a program that accepts marks for 30 students. Each mark must be between 0 and 100 (inclusive). The program should output the average mark and the highest mark.

Step 1 - Analysis:

  • Inputs: 30 marks (each between 0 and 100)
  • Processes: validate each mark, calculate total, find highest
  • Outputs: average mark, highest mark

Step 2 - Design (pseudocode):

Total ← 0
Highest ← 0
FOR Student ← 1 TO 30
  REPEAT
    OUTPUT "Enter mark for student ", Student
    INPUT Mark
  UNTIL Mark >= 0 AND Mark <= 100
  Total ← Total + Mark
  IF Mark > Highest THEN
    Highest ← Mark
  ENDIF
NEXT Student
Average ← Total / 30
OUTPUT "Average: ", Average
OUTPUT "Highest: ", Highest

Step 3 - Identify the patterns used:

  1. Validation: The REPEAT...UNTIL loop rejects marks outside 0-100. This is a range check. The loop forces re-entry until the data is valid.
  2. Totalling: Total accumulates every valid mark.
  3. Finding maximum: Highest is compared against each new mark and updated when a larger value appears.
  4. Counting: The FOR loop itself counts through 30 students, so a separate counter is not needed.

Notice that Highest is initialised to 0. This works here because all valid marks are 0 or above. If the range could include negative numbers, you would initialise Highest to the first actual input value instead.

Validation and Verification

These are two distinct concepts, and the examiners expect you to know the difference.

Validation is an automated check performed by a program to ensure data is reasonable and within expected rules. It does NOT check whether the data is correct - only whether it is acceptable.

Verification checks that data has been accurately transferred or entered. It confirms the data matches what was intended.

Types of Validation

Validation TypeWhat It ChecksExample
Range checkValue falls within a specified rangeMark must be between 0 and 100
Length checkInput has the correct number of charactersPassword must be 8-16 characters
Type checkData is the correct data typeAge must be an integer, not text
Presence checkA required field is not left emptyEmail field cannot be blank
Format checkData matches a required patternDate must be DD/MM/YYYY
Check digitA calculated digit verifies a code is validLast digit of a barcode (ISBN, UPC)

Types of Verification

  • Double entry: The user enters the same data twice (e.g., "confirm your email"). The system compares both entries and flags any mismatch.
  • Screen/visual check: The data is displayed back to the user, who visually confirms it is correct before submission.
Key distinction: A student who enters their age as 152 instead of 15 could pass a type check (it is an integer) and even a presence check (it is not blank), but would fail a range check (if the expected range is 5-19). Validation does not guarantee accuracy. It only ensures the data meets the rules.

Test Data

Testing is the final stage of the development life cycle, and examiners frequently ask you to create a test plan. There are three categories of test data:

  1. Normal data: Valid inputs that the program should accept and process correctly. For a mark between 0 and 100, normal data would be 45, 72, or 88.
  2. Abnormal (erroneous) data: Inputs that the program should reject. For the same range, abnormal data would be -5, 101, or "abc".
  3. Extreme (boundary) data: Values at the very edge of the accepted range. For 0 to 100, the boundary values are 0 and 100 themselves. You should also test the values just outside: -1 and 101.

A complete test plan for a mark-entry program (range 0-100) might look like this:

Test DataTypeExpected Result
50NormalAccepted
0BoundaryAccepted
100BoundaryAccepted
-1AbnormalRejected
101AbnormalRejected
"hello"AbnormalRejected

Common Mistakes

These errors appear repeatedly in student scripts. Avoid them.

  1. Forgetting to initialise variables. If Total is not set to 0 before a loop, it may contain garbage data. Always initialise accumulators, counters, and flags before using them.
  2. Off-by-one errors in loops. A FOR loop from 1 TO 10 runs 10 times. A FOR loop from 0 TO 9 also runs 10 times. But 0 TO 10 runs 11 times. Count carefully.
  3. Confusing validation with verification. Validation checks rules (range, type, length). Verification checks accuracy (double entry, visual check). They are different processes with different purposes.
  4. Missing the temporary variable in a swap. To swap A and B, you need: Temp = A, then A = B, then B = Temp. Skipping the temporary variable destroys one value.
  5. Not testing boundary values. If a question says "between 1 and 50," your test plan must include 1 and 50 as boundary tests. Many students only test values in the middle.
  6. Writing pseudocode without closing keywords. Every IF needs ENDIF. Every WHILE needs ENDWHILE. Every FOR needs NEXT. Missing closers will cost you marks.
  7. Initialising max/min incorrectly. Setting Max to 0 is only safe if all possible values are non-negative. For general data, initialise Max to the first element of the list.

Exam Strategy

Approach for pseudocode questions: Read the problem statement twice. Underline the inputs, outputs, and any conditions. Write the structure (loops, selections) first, then fill in the details. Check your closing keywords. Trace through with one set of test data before moving on.

For trace table questions, work methodically. Draw the table with a column for every variable and one for output. Step through each line of the algorithm. Do not skip steps or try to do multiple iterations in your head at once. Write each change as it happens.

When asked to identify errors in a given algorithm, trace through it with simple test data first. The trace table will reveal where the logic breaks. Common errors to look for include: uninitialised variables, wrong comparison operators (using > instead of >=), and loops that iterate one too many or one too few times.

Self-Check Questions

  1. A program accepts an integer input that must be between 10 and 20 inclusive. Write three pieces of test data: one normal, one boundary, and one abnormal. For each, state whether it should be accepted or rejected.
  2. Explain the difference between validation and verification. Give one example of each.
  3. The following pseudocode is intended to count how many numbers in a list of 5 are greater than 50. Identify the error:

    Count ← 0
    FOR Index ← 1 TO 5
      INPUT Number
      IF Number > 50 THEN
        Count ← 1
      ENDIF
    NEXT Index
    OUTPUT Count
  4. Draw or describe a trace table for a bubble sort algorithm applied to the list [4, 2, 7, 1] during the first complete pass.
  5. Name the four stages of the program development life cycle in the correct order.
Answers at a glance:
1. Normal: 15 (accepted). Boundary: 10 or 20 (accepted). Abnormal: 25 (rejected).
2. Validation is an automated check that data meets rules (e.g., range check on age). Verification checks data was entered correctly (e.g., double entry of email).
3. The error is Count ← 1 should be Count ← Count + 1. As written, Count resets to 1 every time instead of incrementing.
4. After pass 1: compare 4,2 (swap to 2,4); compare 4,7 (no swap); compare 7,1 (swap to 1,7). Result: [2, 4, 1, 7].
5. Analysis, Design, Coding, Testing.

Téléchargez l'application sur Google Play.

Tout ce dont vous avez besoin pour exceller au JAMB, WAEC et NECO.

Green Bridge CBT Mobile App
Assistant de chat d'apprentissage personnalisé par IA
Des milliers d'anciens sujets IGCSE, JAMB, WAEC et NECO.
Plus de 1200 notes de cours
Assistance Hors Ligne - Apprenez à Tout Moment, Partout
Horaire du Pont Vert
Résumés littéraires et questions potentielles
Suivez vos performances et votre progression
Explications Approfondies pour un Apprentissage Complet
Résumé

A thorough revision guide to algorithm design and problem-solving for IGCSE Computer Science (0478), covering the program development life cycle, decomposition, pseudocode, flowcharts, trace tables, standard algorithms, validation, verification, and test data. Includes worked examples, common mistakes, and self-check questions aligned to the Cambridge syllabus.