IGCSE Edexcel Computer Science  |  Unit 1: Programming

1.1
Algorithms

Designing, representing, tracing and evaluating algorithms using flowcharts, pseudocode and standard searching & sorting techniques.

🎯 Guiding Question: "How do we design step-by-step solutions that a computer can follow reliably?"

Unit 1.1 Algorithms Edexcel Pseudocode

Arrow keys or buttons to navigate  |  F11 for full screen

Syllabus Overview

1.1 Algorithms — Specification Points

Understanding & Representation

  • Understand what an algorithm is and its uses
  • Interpret algorithms written as flowcharts, pseudocode, written descriptions and program code
  • Create algorithms using sequence, selection and iteration
  • Determine the purpose of a given algorithm

Tracing & Testing

  • Determine the correct output for a given set of data
  • Identify and correct errors using trace tables
  • Code an algorithm in a high-level language
  • Understand that choice of algorithm is influenced by data structures and values

Standard Algorithms

  • Searching: Linear search, Binary search
  • Sorting: Bubble sort, Merge sort

Evaluation

  • Evaluate fitness for purpose using logical reasoning
  • Assess algorithms using test data
  • Understand efficiency considerations
1.1 — What is an Algorithm?

What is an Algorithm?

An algorithm is a precise, step-by-step set of instructions designed to solve a problem or perform a task.

📋

Finite

Has a definite start and end — it must terminate.

🎯

Unambiguous

Every instruction is clear — no room for misinterpretation.

✅

Effective

Produces the correct output for all valid inputs.

Everyday example: A recipe is an algorithm — ingredients (inputs), steps (process), dish (output). The steps must be followed in the correct order to get the right result.

In computing: Algorithms are used to search databases, sort data, compress files, navigate maps, recommend content, and much more. A good algorithm is correct, efficient, and clear.

1.1 — Representation

Representing Algorithms

Algorithms can be expressed in three main ways. You must be able to read and write all three.

🕐

Flowchart

A visual diagram using standard symbols (ovals, rectangles, diamonds) connected by arrows to show the flow of logic.

Best for: Visualising the logic — especially decisions and loops.

📄

Pseudocode

A structured, English-like notation that describes an algorithm without needing to follow any specific programming language syntax.

Edexcel uses: SET, RECEIVE, SEND, IF…END IF, FOR…END FOR, WHILE…END WHILE, etc.

💻

Program Code

A real programming language such as Python, which a computer can execute (after compilation or interpretation).

In this unit: We will show Edexcel pseudocode and equivalent Python side-by-side.

💡 Tip: In exams you may be asked to write in pseudocode or trace through a flowchart — both skills are assessed.

1.1 — Flowchart Symbols

Standard Flowchart Symbols

START / STOP
Oval (Terminal)
Marks the start or end of the algorithm.
Process
Rectangle (Process)
An action or calculation, e.g. SET Total TO Total + 1
Condition?
Diamond (Decision)
A yes/no question that creates two branches (YES / NO).
Input / Output
Parallelogram (I/O)
Reading input from the user or displaying output.
Flow
Arrow (Flow line)
Shows the direction of flow between steps.

Decision labels: Always label the two exits of a diamond Yes (or True) and No (or False).

1.1 — Flowchart Construction

Flowchart Example: Largest of Three Numbers

START Input A, B, C A > B ? (decision) Yes No A > C ? Yes No B > C ? Yes No L = A L = C L = C L = B Output Largest STOP

Task: Given three numbers A, B and C — find and output the largest.

Logic walkthrough

  1. Input A, B, C from the user
  2. Check if A > B — if yes, compare A with C
  3. If A > C → Largest = A; otherwise Largest = C
  4. If A was not > B, compare B with C
  5. If B > C → Largest = B; otherwise Largest = C
  6. Output the Largest value

Key exam point: Each diamond must have exactly two labelled exits. Never leave a branch unlabelled.

Try it: Trace through with A=7, B=12, C=5. Which path do you follow? What is the output?

1.1 — Tracing a Flowchart

Tracing a Flowchart

Tracing = following the flow of an algorithm step-by-step with specific input values to determine the output.

START SET Count TO 1 Count <= 3? (WHILE loop) Yes Output Count Count = Count + 1 No STOP

Trace Table for Count = 1 to 3

Step Count Count <= 3? Output
Start1--
Check1Yes1
Increment2Yes2
Increment3Yes3
Check4No-
STOPLoop ends

How to trace: Work through each step in order. Record every variable change and any output. Never skip steps.

Exam tip: You will be given input values and asked to complete a trace table — or to find the bug by spotting where the trace goes wrong.

1.1 — Edexcel Pseudocode

Pseudocode Syntax Reference (Edexcel)

Variables & Assignment

SET Counter TO 0
SET Name TO "Alice"
SET Total TO Price * Quantity
SET Arr[0] TO 42

Input / Output

RECEIVE Age FROM (INTEGER) KEYBOARD
RECEIVE Name FROM (STRING) KEYBOARD
SEND "Hello " & Name TO DISPLAY
SEND Total TO DISPLAY

Selection

IF Score >= 70 THEN
    SEND "Pass" TO DISPLAY
ELSE
    SEND "Fail" TO DISPLAY
END IF

Iteration

# Count-controlled
FOR i FROM 1 TO 5 DO
    SEND i TO DISPLAY
END FOR

# Pre-condition
WHILE Count > 0 DO
    SET Count TO Count - 1
END WHILE

# Post-condition
REPEAT
    RECEIVE n FROM (INTEGER) KEYBOARD
UNTIL n > 0

Operators

SymbolMeaning
+ - * /Arithmetic
MODRemainder (e.g. 7 MOD 3 = 1)
DIVInteger division (e.g. 7 DIV 3 = 2)
= <> < > <= >=Comparisons
AND OR NOTLogical
&String concatenation
1.1 — Sequence

Sequence: Calculating the Area of a Rectangle

Sequence = instructions executed one after another, in order, with no branching or repetition. It is the simplest control structure.

Edexcel Pseudocode
# Area of a Rectangle

RECEIVE Length FROM (REAL) KEYBOARD
RECEIVE Width  FROM (REAL) KEYBOARD

SET Area TO Length * Width

SEND "Area = " & Area TO DISPLAY
Python
# Area of a Rectangle

length = float(input("Enter length: "))
width  = float(input("Enter width:  "))

area = length * width

print("Area =", area)

Step 1: Input — receive values from the user.

Step 2: Process — calculate Area = Length × Width.

Step 3: Output — display the result to the screen.

💡 IPO model: Almost every algorithm follows Input → Process → Output. Sequence is the backbone of all programs.

1.1 — Selection

Selection: IF / ELSE

Selection allows an algorithm to make decisions — different instructions are executed depending on whether a condition is true or false.

Edexcel Pseudocode
# Grade classifier

RECEIVE Score FROM (INTEGER) KEYBOARD

IF Score >= 70 THEN
    SEND "Grade: A" TO DISPLAY
ELSE
    IF Score >= 55 THEN
        SEND "Grade: B" TO DISPLAY
    ELSE
        IF Score >= 40 THEN
            SEND "Grade: C" TO DISPLAY
        ELSE
            SEND "Grade: U" TO DISPLAY
        END IF
    END IF
END IF
Python
# Grade classifier

score = int(input("Enter score: "))

if score >= 70:
    print("Grade: A")
elif score >= 55:
    print("Grade: B")
elif score >= 40:
    print("Grade: C")
else:
    print("Grade: U")

Edexcel note: There is no ELIF keyword — nested IF...END IF blocks are used instead. Each IF must be closed with END IF.

Trace check: With Score = 62, which branch executes? Answer: Score < 70 → Score >= 55 → "Grade: B".

🔒
Preview Only
Full presentation available at CSExamReady.com
1.1 — Iteration

Iteration: Repeating Instructions

Iteration (looping) lets a set of instructions execute repeatedly. Edexcel pseudocode has three loop structures — you must know when to use each one.

COUNT-CONTROLLED LOOP — use when you know exactly how many times to repeat

Edexcel Pseudocode
# Print 1 to 5
FOR i FROM 1 TO 5 DO
    SEND i TO DISPLAY
END FOR

# With a step
FOR i FROM 0 TO 20 STEP 5 DO
    SEND i TO DISPLAY
END FOR
Python
# Print 1 to 5
for i in range(1, 6):
    print(i)

# With a step
for i in range(0, 21, 5):
    print(i)

PRE-CONDITION — check first, may never run

WHILE … END WHILE
# Keep asking until valid
RECEIVE n FROM (INTEGER) KEYBOARD
WHILE n <= 0 DO
    SEND "Enter positive number"
        TO DISPLAY
    RECEIVE n FROM (INTEGER)
        KEYBOARD
END WHILE
Python
n = int(input())
while n <= 0:
    print("Enter positive number")
    n = int(input())

POST-CONDITION — runs at least once

REPEAT … UNTIL
# Always runs body first
REPEAT
    SEND "Enter positive number"
        TO DISPLAY
    RECEIVE n FROM (INTEGER)
        KEYBOARD
UNTIL n > 0

💡 Python has no REPEAT-UNTIL equivalent. Python only has while (pre-condition). The common workaround is while True: ... if cond: break — but this is not a built-in loop type.

💡 Exam tip: REPEAT…UNTIL always executes at least once. WHILE may execute zero times if the condition is false from the start. Know which to choose!

🔒
Preview Only
Full presentation available at CSExamReady.com
1.1 — Iteration Flowcharts

WHILE vs REPEAT-UNTIL: Flowchart Comparison

Both loops below print the numbers 1, 2, 3. Notice where the condition diamond appears — that is the key structural difference.

WHILE Loop — condition checked FIRST

May execute zero times if condition is false at the start

START SET Count = 1 ▲ condition checked here Count ≤ 3 ? (WHILE cond) Yes Output Count Count = Count+1 loop back No STOP

Pseudocode: WHILE Count ≤ 3 DO … END WHILE

REPEAT-UNTIL — condition checked LAST

Always executes at least once

START SET Count = 1 ▼ body runs first (always) Output Count Count = Count+1 ▼ condition checked here Count > 3 ? (UNTIL cond) Yes STOP No loop back

Pseudocode: REPEAT … UNTIL Count > 3

⚠ Key difference: If Count started at 4, the WHILE loop body would never run. The REPEAT-UNTIL body would run once, output 4, then exit. Same condition — completely different behaviour!

🔒
Preview Only
Full presentation available at CSExamReady.com
1.1 — Algorithm Purpose

Determining the Purpose of an Algorithm

In the exam you will be given an algorithm and asked "What does this algorithm do?" — you need a strategy to work it out quickly.

🎯 Strategy

  1. Identify the inputs (RECEIVE statements)
  2. Identify the outputs (SEND statements)
  3. Trace through with simple test values
  4. Look for patterns — accumulation, counting, searching, sorting?
  5. Write a concise one-sentence answer

🔍 Mystery Algorithm — what does it do?

SET Total TO 0
SET Count TO 0
RECEIVE n FROM (INTEGER) KEYBOARD
WHILE n <> -1 DO
    SET Total TO Total + n
    SET Count TO Count + 1
    RECEIVE n FROM (INTEGER) KEYBOARD
END WHILE
IF Count > 0 THEN
    SEND Total / Count TO DISPLAY
END IF

Trace with inputs: 8, 4, 6, -1

n (input)TotalCountn ≠ -1?Output
881Yes—
4122Yes—
6183Yes—
-1183No → exit18/3 = 6

Purpose: This algorithm reads a series of integers (terminated by -1) and outputs their arithmetic mean (average). The sentinel value -1 signals the end of input.

🔒
Preview Only
Full presentation available at CSExamReady.com
1.1 — Trace Tables

Trace Tables

A trace table is a method of manually tracking the values of variables and outputs as you execute an algorithm step by step. It is used to verify correctness or locate errors.

How to construct a trace table

  1. Create one column for each variable used in the algorithm
  2. Add an Output column for any SEND/print statements
  3. Execute each line in order, recording changes
  4. Only update a cell when that variable changes value
  5. Record output exactly as it would be displayed

Rules to remember

  • Leave a cell blank if the variable is unchanged on that step
  • Always record the value after the assignment, not before
  • Track loop conditions — record True/False for decision points
  • Show each iteration of a loop as a separate row
  • Used both to test correct algorithms and to find bugs

Example: Trace this algorithm with inputs 3, 7, 2

Algorithm
SET Total TO 0
FOR i FROM 1 TO 3 DO
    RECEIVE num FROM (INTEGER) KEYBOARD
    SET Total TO Total + num
END FOR
SEND Total TO DISPLAY
inumTotalOutput
——0—
133—
2710—
3212—
———12

Output = 12 ✓ (3 + 7 + 2 = 12)

🔒
Preview Only
Full presentation available at CSExamReady.com
1.1 — Finding Errors with Trace Tables

Trace Table: Finding and Fixing a Bug

Trace tables are a powerful tool for locating bugs. When the trace produces an unexpected output, you can pinpoint exactly which line caused the error.

🐞 Buggy Algorithm

Task: read 3 numbers and output their sum.

SET Total TO 1   # Line 1 ← BUG HERE
FOR i FROM 1 TO 3 DO
    RECEIVE num FROM (INTEGER)
        KEYBOARD
    SET Total TO Total + num
END FOR
SEND Total TO DISPLAY

⚠ Line 1: Total is initialised to 1 instead of 0. Every result will be 1 too large.

Trace with inputs: 4, 5, 6

StepinumTotalOutput
Initialise—— 1 ⚠ —
i = 1145—
i = 22510—
i = 33616—
Output——— 16 ⚠

Expected: 4 + 5 + 6 = 15
Actual output: 16 — off by 1

Fix: Change SET Total TO 1 → SET Total TO 0

Another common bug: wrong loop bound

✘ Buggy:

SET Arr TO [3,7,2,9,5]
SET Max TO 0
FOR i FROM 0 TO 3 DO
    IF Arr[i] > Max THEN
        SET Max TO Arr[i]
    END IF
END FOR
SEND Max TO DISPLAY

Misses index 4 (value 5). Should be TO 4.

✔ Fixed:

SET Arr TO [3,7,2,9,5]
SET Max TO 0
FOR i FROM 0 TO 4 DO
    IF Arr[i] > Max THEN
        SET Max TO Arr[i]
    END IF
END FOR
SEND Max TO DISPLAY

Now checks all 5 elements. Output: 9.

🔒
Preview Only
Full presentation available at CSExamReady.com
1.1 — Types of Errors

Types of Programming Errors

Errors in programs fall into three categories. Understanding which type you have tells you how to find and fix it — and trace tables are especially useful for logic errors.

✍

Syntax Error

The code breaks the rules of the language. The interpreter/compiler catches it before the program runs.

✘ Buggy pseudocode:

IF Score > 70        # missing THEN
    SEND "Pass" TO DISPLAY
END IF

✔ Fixed:

IF Score > 70 THEN
    SEND "Pass" TO DISPLAY
END IF

Other examples: misspelled keywords, missing END FOR, unmatched brackets.

💥

Runtime Error

The program starts running but crashes at some point due to an impossible operation.

✘ Example:

RECEIVE count FROM (INTEGER) KEYBOARD
SET result TO 10 / count
# If user enters 0 → crash!

✔ Fixed with guard:

IF count <> 0 THEN
    SET result TO 10 / count
END IF

Other examples: array index out of bounds, reading a file that doesn't exist.

🧠

Logic Error

The program runs without crashing but produces the wrong output. The hardest type to find — use a trace table!

✘ Example:

IF age > 18 THEN   # excludes age=18!
    SEND "Adult" TO DISPLAY
END IF

✔ Fixed:

IF age >= 18 THEN
    SEND "Adult" TO DISPLAY
END IF

Other examples: wrong formula, loop runs one time too many/few.

Error Type When detected? Program runs? How to find it?
Syntax Before running (compile/parse time) No Read the error message from the interpreter
Runtime During execution Partially Check what inputs cause the crash; add guards
Logic Never caught automatically Yes (wrongly) Trace table, test data, desk-checking
🔒
Preview Only
Full presentation available at CSExamReady.com
1.1 — Standard Algorithms

Linear Search

A linear search checks each element of a list one by one, from the first to the last, until the target is found or the list is exhausted. It works on any list — sorted or unsorted.

Edexcel Pseudocode
# Linear Search
# Find target in array Arr of size N

SET Found TO FALSE
SET Index TO 0

WHILE Index < N AND Found = FALSE DO
    IF Arr[Index] = Target THEN
        SET Found TO TRUE
    ELSE
        SET Index TO Index + 1
    END IF
END WHILE

IF Found = TRUE THEN
    SEND "Found at index " & Index TO DISPLAY
ELSE
    SEND "Not found" TO DISPLAY
END IF
Python
arr    = [14, 3, 27, 9, 42, 7]
target = 9
found  = False
index  = 0

while index < len(arr) and not found:
    if arr[index] == target:
        found = True
    else:
        index += 1

if found:
    print("Found at index", index)
else:
    print("Not found")

Trace: search for 9 in [14, 3, 27, 9, 42, 7]

IndexArr[Index]= Target (9)?FoundAction
014NoFALSEIndex → 1
13NoFALSEIndex → 2
227NoFALSEIndex → 3
39Yes ✓TRUEOutput "Found at index 3"

Advantages: Simple to code; works on unsorted data; no pre-processing needed.

Disadvantages: Slow for large lists — worst case checks every element. Time grows linearly with list size (O(n)).

🔒
Preview Only
Full presentation available at CSExamReady.com
1.1 — Standard Algorithms

Binary Search

A binary search repeatedly halves the search space by comparing the target to the middle element. It is much faster than linear search — but the list must be sorted first.

Edexcel Pseudocode
# Binary Search (sorted array)
SET Low  TO 0
SET High TO N - 1
SET Found TO FALSE

WHILE Low <= High AND Found = FALSE DO
    SET Mid TO (Low + High) DIV 2
    IF Arr[Mid] = Target THEN
        SET Found TO TRUE
    ELSE
        IF Target < Arr[Mid] THEN
            SET High TO Mid - 1
        ELSE
            SET Low TO Mid + 1
        END IF
    END IF
END WHILE

IF Found = TRUE THEN
    SEND "Found at index " & Mid TO DISPLAY
ELSE
    SEND "Not found" TO DISPLAY
END IF
Python
# List MUST be sorted
arr    = [3, 7, 9, 14, 27, 42]
target = 9
low    = 0
high   = len(arr) - 1
found  = False

while low <= high and not found:
    mid = (low + high) // 2
    if arr[mid] == target:
        found = True            # found
    elif target < arr[mid]:
        high = mid - 1          # search left half
    else:
        low  = mid + 1          # search right half

if found:
    print("Found at index", mid)
else:
    print("Not found")

Trace: search for 9 in [3, 7, 9, 14, 27, 42]  (indices 0–5)

StepLowHighMidArr[Mid]Compare to 9Action
10529= Target ✓Found at index 2

Found in just 1 step! Compare: linear search would have taken 3 steps.

Example where more steps are needed — search for 27:

StepLowHighMidArr[Mid]Compare to 27Action
1052927 > 9Low = 3
235427= Target ✓Found at index 4

Advantages: Very fast — halves the search space each step. Max steps = log₂(n). For 1 million items: only ~20 comparisons.

Disadvantages: List must be sorted before searching. Sorting takes extra time. More complex to code than linear search.

🔒
Preview Only
Full presentation available at CSExamReady.com
1.1 — Standard Algorithms

Bubble Sort

Bubble sort repeatedly steps through the list, compares adjacent pairs, and swaps them if they are in the wrong order. Larger values "bubble up" to the end with each pass.

Edexcel Pseudocode
# Bubble Sort (ascending order)
SET N TO LENGTH(Arr)
SET Swapped TO TRUE

WHILE Swapped = TRUE DO
    SET Swapped TO FALSE
    FOR i FROM 0 TO N - 2 DO
        IF Arr[i] > Arr[i + 1] THEN
            # Swap adjacent elements
            SET Temp    TO Arr[i]
            SET Arr[i]  TO Arr[i + 1]
            SET Arr[i + 1] TO Temp
            SET Swapped TO TRUE
        END IF
    END FOR
    SET N TO N - 1  # last item now in place
END WHILE
Python
arr     = [5, 3, 8, 1, 9, 2]
n       = len(arr)
swapped = True

while swapped:
    swapped = False
    for i in range(n - 1):
        if arr[i] > arr[i + 1]:
            # Swap adjacent elements
            temp        = arr[i]
            arr[i]      = arr[i + 1]
            arr[i + 1]  = temp
            swapped     = True
    n -= 1  # last element now in place

print(arr)  # → [1, 2, 3, 5, 8, 9]

Trace: sort [5, 3, 8, 1, 9, 2] — pass by pass

PassArray after passSwaps made?Sorted position
Start [5, 3, 8, 1, 9, 2]——
Pass 1 [3, 5, 1, 8, 2, 9] YesIndex 5 → 9 fixed
Pass 2 [3, 1, 5, 2, 8, 9] YesIndex 4 → 8 fixed
Pass 3 [1, 3, 2, 5, 8, 9] YesIndex 3 → 5 fixed
Pass 4 [1, 2, 3, 5, 8, 9] YesIndex 2 → 3 fixed
Pass 5 [1, 2, 3, 5, 8, 9] No swapsFully sorted — stop early

💡 The Swapped flag is an optimisation — if no swaps occur in a pass, the list is already sorted and the algorithm stops early instead of making unnecessary passes.

Advantages: Simple to understand and code; detects already-sorted lists quickly (with Swapped flag); works in-place (no extra memory needed).

Disadvantages: Slow on large lists — worst case O(n²) comparisons. Not suitable for large datasets. Merge sort is significantly more efficient.

🔒
Preview Only
Full presentation available at CSExamReady.com
1.1 — Standard Algorithms

Merge Sort

Merge sort uses a divide and conquer strategy: repeatedly split the list in half until each piece has one element, then merge the pieces back together in sorted order.

How it works

  1. Split: Divide the list into two halves
  2. Keep splitting each half until every sublist has one element (a list of one is always sorted)
  3. Merge: Compare the first elements of two sublists; take the smaller one; repeat until both are merged into one sorted list
  4. Keep merging until the whole list is rebuilt — sorted

Splitting [38, 27, 43, 3, 9, 82]

[38, 27, 43, 3, 9, 82]
↙                     ↘
[38, 27, 43] [3, 9, 82]
↙   ↘         ↙   ↘
[38] [27,43] [3] [9,82]
        ↙  ↘           ↙  ↘
[27] [43] [9] [82]
↑ single elements — now merge back up ↑
Edexcel Pseudocode — Merge step
# Merge two sorted lists A and B into C
SET i TO 0
SET j TO 0
SET C TO []

WHILE i < LENGTH(A) AND j < LENGTH(B) DO
    IF A[i] <= B[j] THEN
        SET C TO C & A[i]
        SET i TO i + 1
    ELSE
        SET C TO C & B[j]
        SET j TO j + 1
    END IF
END WHILE

# Append any remaining elements
WHILE i < LENGTH(A) DO
    SET C TO C & A[i]
    SET i TO i + 1
END WHILE
WHILE j < LENGTH(B) DO
    SET C TO C & B[j]
    SET j TO j + 1
END WHILE
Python — Merge step
A = [27, 38, 43]   # sorted left half
B = [3, 9, 82]    # sorted right half
C = []
i = 0
j = 0

while i < len(A) and j < len(B):
    if A[i] <= B[j]:
        C.append(A[i])
        i += 1
    else:
        C.append(B[j])
        j += 1

# Append leftover elements
while i < len(A):
    C.append(A[i])
    i += 1
while j < len(B):
    C.append(B[j])
    j += 1

print(C)  # → [3, 9, 27, 38, 43, 82]

Advantages: Much faster than bubble sort for large lists — O(n log n). Consistent performance regardless of initial order.

Disadvantages: More complex to code. Requires extra memory to hold the temporary sublists during merging.

🔒
Preview Only
Full presentation available at CSExamReady.com
1.1 — Algorithm Comparison

Comparing Algorithms

The choice of algorithm depends on the data: its size, whether it is sorted, and how often the search or sort needs to run. There is no single "best" algorithm for all situations.

Searching: Linear vs Binary

FactorLinear SearchBinary Search
Data must be sorted?No — works on any listYes — list must be sorted first
Speed (small list)Similar — difference negligibleSimilar — overhead not worth it
Speed (large list)Slow — checks every item (O(n))Fast — halves search space (O(log n))
Worst case (1000 items)Up to 1000 comparisonsUp to 10 comparisons
Best forSmall or unsorted datasets; one-off searchesLarge sorted datasets; repeated searches

Sorting: Bubble Sort vs Merge Sort

FactorBubble SortMerge Sort
ComplexitySimple to understand and codeMore complex — divide & conquer
Speed (small list)Fine — simple and fast enoughSlight overhead from splitting
Speed (large list)Very slow — O(n²) comparisonsMuch faster — O(n log n)
Memory useIn-place — no extra memoryNeeds extra memory for sublists
Best forSmall lists; teaching; nearly-sorted dataLarge datasets where speed matters

💡 Exam tip: When asked to justify a choice of algorithm, always link to the data characteristics — size, whether it is sorted, and how often the operation runs. "Binary search is better because the list is large and already sorted" scores marks. "Binary search is faster" alone does not.

🔒
Preview Only
Full presentation available at CSExamReady.com
1.1 — Evaluating Algorithms

Fitness for Purpose & Test Data

An algorithm is fit for purpose if it produces the correct output for all valid inputs, handles edge cases correctly, and performs efficiently enough for its intended use.

Evaluating with Logical Reasoning

  • Correctness: Does it always produce the right answer? Trace through with examples.
  • Efficiency: Does it terminate in reasonable time? Avoid unnecessary loops.
  • Clarity: Is it easy to read, maintain and adapt?
  • Robustness: Does it handle unexpected or boundary inputs without crashing?

Types of Test Data

TypeDescriptionExample (age 0–120)
Normal Typical valid input 25, 40, 67
Boundary Values at the edge of the valid range 0, 1, 119, 120
Erroneous Invalid input that should be rejected -1, 121, "abc"

Worked Example — evaluating a grade algorithm

RECEIVE Score FROM (INTEGER) KEYBOARD
IF Score >= 70 THEN
    SEND "A" TO DISPLAY
ELSE
    IF Score >= 55 THEN
        SEND "B" TO DISPLAY
    ELSE
        IF Score >= 40 THEN
            SEND "C" TO DISPLAY
        ELSE
            SEND "U" TO DISPLAY
        END IF
    END IF
END IF
Test typeInputExpectedPass?
Normal75A✓
Normal50C✓
Boundary70A✓
Boundary40C✓
Boundary39U✓
Erroneous-5Rejected✗ — outputs U!

Not fully fit for purpose — erroneous input (-5) is not validated. A guard clause checking 0 <= Score <= 100 is needed.

🔒
Preview Only
Full presentation available at CSExamReady.com
Exam Practice — Questions (Q1–Q4)

Exam-Type Questions

1

State what is meant by an algorithm and give one characteristic it must have.

[2 marks]
2

The algorithm below is intended to find the largest of three numbers A, B and C. Trace through it with A = 4, B = 9, C = 6 and complete the trace table.

[3 marks]
IF A > B THEN
    IF A > C THEN
        SET Largest TO A
    ELSE
        SET Largest TO C
    END IF
ELSE
    IF B > C THEN
        SET Largest TO B
    ELSE
        SET Largest TO C
    END IF
END IF
SEND Largest TO DISPLAY
ABCA > B?B > C?LargestOutput
496                    
3

Identify the type of error in the following pseudocode and describe how to fix it.

[3 marks]
SET Total TO 0
FOR i FROM 1 TO 5 DO
    RECEIVE num FROM (INTEGER) KEYBOARD
    SET Total TO Total - num
END FOR
SEND Total TO DISPLAY

Hint: what should happen to Total when a number is received?

4

A list contains 512 items. Compare the maximum number of comparisons needed to find an item using (a) linear search and (b) binary search. The list is already sorted.

[4 marks]
🔒
Preview Only
Full presentation available at CSExamReady.com
Exam Practice — Questions (Q5–Q7)

Exam-Type Questions (continued)

5

The array below is to be sorted into ascending order using bubble sort.
Show the array after each complete pass until no more swaps are needed.

[4 marks]

Starting array:  [7, 2, 5, 1, 8]

PassArray after passSwaps made?
Start[7, 2, 5, 1, 8]—
1  
2  
3  
4  
6

Write pseudocode for a linear search that searches for a value entered by the user in an array called Items of size 8. Output the index if found, or "Not found" otherwise.

[5 marks]
7

A programmer tests a grade-checking program with the inputs below. Identify the type of test data for each and explain why each is used.

[6 marks]
Input valueType of test dataReason for using it
65                     
0  
-10  
🔒
Preview Only
Full presentation available at CSExamReady.com
Exam Practice — Answers (Q1–Q4)

Sample Answers (Q1–Q4)

1

An algorithm is a precise, step-by-step set of instructions for solving a problem or completing a task. [1 mark]

One characteristic (any one of): it must be finite (terminates); unambiguous (every step is clear); effective (produces the correct result for all valid inputs). [1 mark]

2

Trace with A=4, B=9, C=6:

ABCA > B?B > C?LargestOutput
496NoYes99

A > B is False → go to ELSE branch → B > C is True → Largest = B = 9 ✓

3

Error type: Logic error — the program runs without crashing but gives the wrong output. [1 mark]

Problem: Line 4 uses Total TO Total - num (subtracts) instead of adding. [1 mark]

Fix: Change to SET Total TO Total + num [1 mark]

4

(a) Linear search: Maximum 512 comparisons — must check every item in the worst case. [1 mark]

(b) Binary search: Maximum 9 comparisons — log₂(512) = 9. Each comparison halves the remaining search space. [1 mark]

Conclusion: Binary search is significantly faster for a sorted list of this size — 9 comparisons vs up to 512. [1 mark]

Requirement: Binary search requires the list to be sorted first; linear search does not. [1 mark]

🔒
Preview Only
Full presentation available at CSExamReady.com
Exam Practice — Answers (Q5–Q7)

Sample Answers (Q5–Q7)

5

Bubble sort passes on [7, 2, 5, 1, 8]:

PassArray after passSwaps?
Start[7, 2, 5, 1, 8]—
1[2, 5, 1, 7, 8]Yes
2[2, 1, 5, 7, 8]Yes
3[1, 2, 5, 7, 8]Yes
4[1, 2, 5, 7, 8]No → stop

Gold values indicate elements confirmed in their final sorted position after each pass.

6

Linear search pseudocode:

RECEIVE Target FROM (INTEGER) KEYBOARD
SET Found TO FALSE
SET Index TO 0

WHILE Index < 8 AND Found = FALSE DO
    IF Items[Index] = Target THEN
        SET Found TO TRUE
    ELSE
        SET Index TO Index + 1
    END IF
END WHILE

IF Found = TRUE THEN
    SEND Index TO DISPLAY
ELSE
    SEND "Not found" TO DISPLAY
END IF

Award 1 mark each for: correct initialisation; WHILE condition with both checks; IF comparison inside loop; incrementing index; correct output both branches.

7
InputTypeReason
65 Normal Typical valid input — checks the algorithm works correctly for expected values [1 mark]
0 Boundary At the lower edge of the valid range — checks the algorithm handles the minimum value correctly [1 mark]
-10 Erroneous Invalid input outside the accepted range — checks the algorithm rejects or handles invalid data without crashing [1 mark]