CS1: Representing Algorithms
How to write and represent algorithms using pseudo-code, flowcharts, decomposition, and abstraction.
How to write and represent algorithms using pseudo-code, flowcharts, decomposition, and abstraction.
Algorithms can be represented in several ways:
name ← "Alice" age ← 16 total ← price * quantity
IF age >= 18 THEN
OUTPUT "You can vote"
ELSE
OUTPUT "You cannot vote"
ENDIF
FOR counter ← 1 TO 10
OUTPUT counter
NEXT counter
WHILE password <> "secret"
INPUT "Enter password: ", password
ENDWHILE
REPEAT
INPUT "Enter age (1-120): ", age
UNTIL age >= 1 AND age <= 120
INPUT "Enter your name: ", name OUTPUT "Hello " & name
| Construct | Pseudo-code Syntax | Purpose |
|---|---|---|
| Assignment | variable ← value | Store a value in a variable |
| Input | INPUT prompt, variable | Get data from the user |
| Output | OUTPUT expression | Display data to the user |
| Selection | IF...THEN...ELSE...ENDIF | Make a decision |
| Counted loop | FOR...TO...NEXT | Repeat a set number of times |
| Condition loop | WHILE...ENDWHILE | Repeat while condition is true |
| Post-test loop | REPEAT...UNTIL | Repeat until condition is true |
| Name | Shape | Purpose | Example Content |
|---|---|---|---|
| Terminator | Oval / Rounded rectangle | START and END of the algorithm | START, STOP |
| Process | Rectangle | Calculations, assignments, operations | total ← total + 1 |
| Decision | Diamond | Yes/No or True/False questions | Is age >= 18? |
| Input/Output | Parallelogram | Getting input or producing output | INPUT name, OUTPUT result |
| Flow lines | Arrows | Show the direction of flow | Arrows connecting symbols |
START | INPUT number | IS number >= 0? |-- YES --> OUTPUT "Positive or zero" |-- NO --> OUTPUT "Negative" | STOP
Big problem: Create a quiz game
Sub-problems:
Big problem: Build a student registration system
Sub-problems:
Full reality: A real landscape has buildings, people, animals, trees, roads, rivers...
Abstracted version (weather map): Only shows temperature, rainfall, wind direction - everything else is removed because it is not relevant to weather forecasting.
The tube map does not show exact geographical positions or distances. It abstracts away these details and only shows the order of stations and interchange points, which is what passengers actually need.
| Real World | Abstracted Model | Removed Detail |
|---|---|---|
| Physical road network | Graph of nodes and edges | Road surface, width, scenery |
| A football match | Score, time, teams | Individual player movements, crowd noise |
| A school | Student records system | Building layout, uniform colour |
Problem: Calculate the average of three test scores
| Component | Description |
|---|---|
| Input | Three test scores (score1, score2, score3) |
| Processing | Add the three scores together, divide by 3 |
| Output | The average score |
INPUT score1 INPUT score2 INPUT score3 total ← score1 + score2 + score3 average ← total / 3 OUTPUT average
Problem: Check if a password is at least 8 characters long
| Component | Description |
|---|---|
| Input | A password string |
| Processing | Find the length of the password, compare to 8 |
| Output | Whether the password is valid or not |
INPUT password
IF LENGTH(password) >= 8 THEN
OUTPUT "Password accepted"
ELSE
OUTPUT "Password too short"
ENDIF
| Feature | Decomposition | Abstraction |
|---|---|---|
| What it does | Breaks a problem into smaller parts | Removes unnecessary detail |
| Goal | Make each part manageable | Focus on essentials only |
| Result | Multiple sub-problems | A simplified model |
| Example | Splitting a game into graphics, logic, input | Representing a city as just coordinates |
| When to use | Complex problems with many parts | Problems with too much irrelevant detail |
Q1: What shape is used in a flowchart to represent a decision?
Q2: Write pseudo-code that asks the user for a number and outputs "Even" if it is divisible by 2, or "Odd" if it is not.
Q3: Explain the difference between decomposition and abstraction.
Q4: A program needs to calculate the area of a rectangle. Identify the inputs, processing and outputs.
Q5: Decompose the problem of creating an online shopping system into at least four sub-problems.
INPUT number
IF number MOD 2 = 0 THEN
OUTPUT "Even"
ELSE
OUTPUT "Odd"
ENDIF
✗ Using = instead of ← for assignment in pseudo-code ✓ In pseudo-code, use the left-arrow ← for assignment; = is used for comparison in conditions.
✗ Thinking pseudo-code must follow exact Python/Java syntax ✓ Pseudo-code is language-independent structured English; it describes logic without strict syntax rules.
✗ Forgetting that flowchart decision boxes must have exactly two exits ✓ Every diamond (decision) must have exactly two paths: Yes and No. A decision with one exit is invalid.
✗ Confusing decomposition with abstraction ✓ Decomposition breaks a problem into smaller sub-problems; abstraction removes unnecessary detail to simplify.
A teacher wants to create an algorithm to calculate the average test score for a class of 30 students. Explain how you would use decomposition and abstraction to design this algorithm. [6 marks]
Decomposition: I would break the problem into sub-problems: (1) Input each student's score, (2) Calculate the total of all scores, (3) Divide the total by 30 to find the average, (4) Output the result. Abstraction: I would remove unnecessary details such as student names, the subject of the test, and the date — only the numeric scores are needed to calculate an average. I would also assume all 30 students took the same test, ignoring any absent students. By decomposing, each sub-problem can be solved and tested independently. By abstracting, the algorithm focuses only on the essential data (scores) and ignores irrelevant information.
AO1 (Computational Thinking — 40%): Demonstrate knowledge and understanding of the principles and concepts of computer science, including representing algorithms, pseudo-code and flowcharts for AQA 8525, OCR J277 & Edexcel 1CP2.
AO2 (Application — 40%): Apply knowledge and understanding of computer science, including representing algorithms, pseudo-code and flowcharts to analyse problems in computational terms and to design, write and evaluate solutions.
AO3 (Evaluation — 20%): Evaluate the effectiveness, correctness and efficiency of computational solutions, including representing algorithms, pseudo-code and flowcharts, and make reasoned judgements about trade-offs.
Get the best revision books and guides to boost your grades.