week 5
1.2.7 How to determine the output of an algorithm given an input.
1.2.8 How to identify errors in an algorithm.
What is an Algorithm Error?
An error in an algorithm is a mistake in its logic or design that causes it to behave unexpectedly - producing incorrect, incomplete, or no results.
These errors can happen before programming (in pseudocode or flowcharts) or after (in the coded version).
Finding errors early is vital - it saves time, reduces system faults, and improves efficiency.
2. Types of Errors You Might Find
a) Logical Errors
-
These occur when the logic or order of steps is wrong, even though the syntax (format) looks fine.
-
The algorithm runs but gives the wrong result.
-
Example:
INPUT number OUTPUT number * 2Intended to square the number, but instead doubles it — a logical error.
How to spot it:
Run through sample data manually and compare the output to what’s expected.
b) Syntax or Structure Errors
-
These happen when rules of structure are broken — like missing an “END IF” in pseudocode or an arrow in a flowchart.
-
The algorithm can’t be followed correctly.
How to spot it:
Check for missing connectors, mismatched conditions, or incorrect flowchart symbols.
In code, this is like a compiler or interpreter error.
c) Runtime or Loop Errors
-
These occur while the algorithm is running, often caused by infinite loops or invalid operations (e.g., dividing by zero).
-
The algorithm “hangs,” “crashes,” or never completes.
How to spot it:
Trace the algorithm with different data sets to see if any loops never end or if calculations fail.
d) Input/Output Errors
-
Caused by misunderstanding what type or range of data is expected.
-
Example: expecting a number but getting a string like “five”.
How to spot it:
Check data types and use validation — make sure inputs match the algorithm’s expected format.
3. Techniques for Finding Errors
a) Dry Running
Dry running means manually stepping through the algorithm using sample data.
You record the value of each variable at each step — usually in a trace table.
| Step | Input | Calculation | Output | Comment |
|---|---|---|---|---|
| 1 | 5 | 5 * 2 | 10 | Works as expected |
| 2 | 5 | 5 * 5 | 25 | Correct after fix |
This helps you see exactly where results start going wrong.
b) Desk Checking
Desk checking is a mental simulation of how an algorithm behaves.
You check:
-
Does the logic make sense?
-
Are decisions handled correctly?
-
Do loops terminate properly?
This is often done before coding.
c) Tracing
Tracing uses visual tools like flowcharts or debugging output statements to show how the algorithm executes each step.
For example, printing variable values at each stage or watching arrows in a flowchart helps find where it deviates from expected logic.
d) Testing
Testing means running the algorithm with different test data sets:
-
Normal data: expected input values
-
Boundary data: at the limit of what’s acceptable
-
Erroneous data: invalid input to see if it’s handled correctly
This confirms whether logic and validation work properly.
4. Step-by-Step Process for Error Identification
-
Read the algorithm carefully.
Understand what it should do — this is your baseline. -
Predict the output.
Before running it, say what the output should be for specific inputs. -
Trace the algorithm manually.
Use a trace table to record variable values and check for unexpected results. -
Identify mismatches.
If the actual output doesn’t match your prediction, find which step caused the change. -
Check control structures.
Are sequence, selection, and iteration correctly used? -
Revise and re-test.
Make corrections and test again until results match the intended outcome.
5. Example:
Algorithm (in pseudocode):
INPUT number WHILE number > 0 total = total + number END WHILE OUTPUT total
Expected behaviour:
To add up positive numbers entered by the user.
Problem:
The algorithm doesn’t reduce number inside the loop — it becomes infinite.
Fix:
Add a line number = number - 1 inside the loop.
6. Summary Table
| Error Type | Example | How to Find It |
|---|---|---|
| Logical | Wrong calculation order | Dry run or trace |
| Syntax | Missing END IF | Desk check structure |
| Runtime | Infinite loop | Test or simulate |
| Input/Output | Wrong data type | Test with sample inputs |
1.2.9 How to correct errors in an algorithm.
1.2.10 How to design algorithms and solutions that use actions.
What Are Actions in Algorithms?
In an algorithm, actions are the individual operations or commands that make the system do something.
They are the steps that make change happen.
Examples of actions include:
-
Input: getting data from a user or system
-
Processing: performing calculations or transformations
-
Output: showing or sending results
-
Control: repeating or deciding what happens next
Think of actions as the verbs in an algorithm — they describe what actually occurs.
2. The Four Common Types of Actions
| Action Type | Purpose | Example in Pseudocode |
|---|---|---|
| Input | Collects data from user or system | INPUT temperature |
| Process | Calculates or transforms data | average = (num1 + num2 + num3)/3 |
| Selection | Makes a decision based on a condition | IF password = storedPassword THEN access = "granted" |
| Iteration | Repeats actions until a condition is met | FOR i = 1 TO 10PRINT iNEXT i |
| Output | Displays or returns results | OUTPUT "Your total is ", total |
When designing an algorithm, you combine these actions logically to create a sequence of operations that solve a problem.
3. How to Design Algorithms Using Actions
Step 1: Define the Problem Clearly
What needs to be solved?
Example: Calculate the total cost of items including VAT.
Step 2: Identify the Inputs and Outputs
-
Input: item prices, VAT rate
-
Output: total cost with VAT
Step 3: Break Down the Processing Steps
Think of the actions needed to transform input into output.
Example sequence of actions:
-
Ask the user for prices.
-
Add them together.
-
Multiply the total by VAT rate.
-
Display the result.
Step 4: Choose Control Structures
Decide whether you need:
-
Sequence: Steps done in order
-
Selection: Choices (e.g. apply discount if total > £50)
-
Iteration: Repeats (e.g. add prices for multiple items)
Step 5: Represent as Pseudocode or Flowchart
You can design algorithms using flowcharts or pseudocode to show the actions clearly.
4. Worked Example 1 – Using Actions in Pseudocode
Problem: Calculate the average of three test scores.
INPUT score1 INPUT score2 INPUT score3 total = score1 + score2 + score3 average = total / 3 OUTPUT "The average score is", average
Actions Used:
-
Input: get the scores
-
Process: add and divide
-
Output: show the result
5. Worked Example 2 – Using Actions with Decisions and Loops
Problem: Create an algorithm that checks whether a user’s password is correct, with three attempts allowed.
attempts = 0 WHILE attempts < 3 INPUT password IF password = "Cyber123" THEN OUTPUT "Access Granted" STOP ELSE OUTPUT "Incorrect password" attempts = attempts + 1 END IF END WHILE OUTPUT "Account locked"
Actions Used:
-
Input: user enters password
-
Process: compare input to stored password
-
Selection: choose different actions based on condition
-
Iteration: loop gives up to 3 attempts
-
Output: display results or lock message
6. Designing Effective Solutions
When designing algorithms using actions:
-
Keep steps clear and simple
-
Use comments or labels to explain what each action does
-
Check that every input has a purpose and every output is supported by process steps
-
Test the algorithm with sample data to ensure all actions work together correctly
“Action Architect Challenge”
Duration: 20 minutes
Type: Individual or pair work
Scenario:
You have been asked to design an algorithm for a college system that calculates a student’s final grade.
The system must:
1. Ask the student for three assignment scores
2. Work out the average score
3. Display a grade based on this scale:
70–100 → “Distinction”
50–69 → “Merit”
30–49 → “Pass”
Below 30 → “Fail”
Design an algorithm using actions (input, process, selection, and output) to solve this problem.
You must:
1. Write your algorithm as pseudocode or draw it as a flowchart.
2. Identify each action type (label them as Input, Process, Selection, Output).
3. Test your algorithm using three different sets of scores to check that it works correctly.
4. Write a short reflection:
How did you decide on the sequence of actions?
Which action type was most important and why?
Extension (optional)
Add iteration: allow the program to repeat for multiple students until the user types “STOP.”
1.3 Strategies
1.3.1 The different approaches to solving problems and understand their purpose and when they are used:
- • top-down
• bottom-up
• modularisation.
1.3.2 The benefits and drawbacks of using the different approaches to solving problems
Last Updated
2025-10-14 15:41:38
English and Maths
English
Maths
Stretch and Challenge
Stretch and Challenge
- Fast to implement
- Accessible by default
- No dependencies
Homework
Homework
Equality and Diversity Calendar
How to's
How 2's Coverage
Links to Learning Outcomes |
Links to Assessment criteria |
|
|---|---|---|
Files that support this week
Week 4←
PrevWeek 5←
PrevWeek 6←
Prev→
Next