Algorithm Design

This is the most heavily assessed part of the exam. You must be able to design, trace, refine, and debug algorithms using flowcharts, pseudocode, and trace tables.

1. Designing Algorithms

Inputs, Processes, and Outputs (IPO)

Every algorithm generally follows this flow. If asked to analyse a login screen:

Inputs

The data going in. E.g. Username and Password typed by the user.

Processes

The calculations or checks. E.g. Checking if the password matches the database.

Outputs

The results returned. E.g. A "Login Successful" message on screen.

Flowchart Symbols

You must use the correct standard symbols when drawing flowcharts in the exam.

Start / End
Terminal
Wait() / Print()
Input / Output
X = X + 1
Process
Is X > 5?
(Y/N)
Decision

Examiner's Eye - Avoid the Trap!

When drawing a flowchart, you must draw directional arrows on your flow lines. A line without an arrowhead is not a valid flowchart connection and will lose marks.

2. Tracing Algorithms

A trace table tracks the value of variables as the programme runs line-by-line.

Algorithm

01count = 1
02total = 0
03while count <= 3:
04total = total + count
05count = count + 1
06print(total)

Output Trace Table

Line count total Output

Examiner's Eye - Avoid the Trap!

When filling in a trace table, do not skip lines. You must update variables exactly in the order the loop executes them, usually one row per iteration.

Interactive Debugging Challenge

Stretch (Grade 9)

Scenario: A SysAdmin has written a security algorithm to ensure a user's chosen PIN is exactly 4 digits long. It contains a Logic Error.

Current Output: If user enters '123456', it incorrectly says "PIN Accepted".

line 01: userPin = input("Enter PIN: ")
line 02: if length(userPin) :
print("PIN Accepted")
else:
print("Error: PIN must be 4 digits")
Result Goes Here

Examiner's Eye - Avoid the Trap!

Syntax vs Logic: Syntax errors stop the code from running (e.g. missing brackets). Logic errors allow the code to run, but produce the wrong output (e.g. using + instead of -).

In J277, it is no longer enough to just point out a logic error. The exam will ask you to "Suggest a fix". You must physically write out the corrected line of code in the answer box.

Written Exam Scenario (AO2/AO3)

"Write an algorithm that asks a user for their age. If the user is 12 or younger, output 'Child Ticket: £5'. If they are over 12, output 'Adult Ticket: £10'."

Check Your Understanding

1. When drawing a flowchart for an algorithm, which standard symbol should be used to represent an Action or Process (e.g., calculations like X = X + 1)?

2. A programmer spells 'WHILE' incorrectly as 'WHIEL'. Which type of error is this?