You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson introduces the concept of algorithms and how they can be represented, covering the key knowledge required for OCR J277 Section 2.2. Understanding algorithms is fundamental to computational thinking and is central to both Paper 1 and Paper 2 of the OCR GCSE Computer Science exam.
An algorithm is a finite sequence of well-defined, step-by-step instructions designed to perform a specific task or solve a particular problem. Algorithms are not computer programs — they are abstract descriptions of a process that can be implemented in any programming language or even followed by a person.
Key properties of an algorithm:
| Property | Description |
|---|---|
| Finite | It must eventually terminate after a finite number of steps |
| Definite | Each step must be precisely and unambiguously defined |
| Inputs | It may have zero or more inputs |
| Outputs | It must produce at least one output |
| Effective | Each step must be basic enough to be carried out |
OCR Exam Tip: If asked to "state what is meant by an algorithm", always mention that it is a set of step-by-step instructions to solve a problem or complete a task. The word "step-by-step" is crucial for full marks.
Before writing any code, programmers plan their solutions using algorithms. This is part of computational thinking, which involves:
By planning with algorithms first, programmers can identify potential issues early and ensure their solution is logical before committing to code.
Pseudocode is a way of writing algorithms using a structured, English-like syntax that resembles a programming language but is not tied to any specific one. OCR uses its own pseudocode reference language in exams.
Here is an example of a simple algorithm in OCR pseudocode that finds the largest of three numbers:
a = input("Enter first number: ")
b = input("Enter second number: ")
c = input("Enter third number: ")
if a >= b AND a >= c then
print("Largest is " + a)
elseif b >= a AND b >= c then
print("Largest is " + b)
else
print("Largest is " + c)
endif
And the equivalent in Python:
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a >= b and a >= c:
print("Largest is", a)
elif b >= a and b >= c:
print("Largest is", b)
else:
print("Largest is", c)
OCR Exam Tip: In the exam, you may be asked to write, complete, or interpret pseudocode. You do not need to write perfect Python — OCR's pseudocode reference language is accepted. However, you must be consistent in whichever style you use.
A flowchart is a graphical representation of an algorithm using standard symbols:
| Symbol | Shape | Purpose |
|---|---|---|
| Terminator | Rounded rectangle (oval) | Start or end of the algorithm |
| Process | Rectangle | An instruction or action to perform |
| Decision | Diamond | A yes/no or true/false question |
| Input/Output | Parallelogram | Data being entered or displayed |
| Flow line | Arrow | Shows the direction of flow |
A flowchart for this algorithm would flow as follows:
| Feature | Pseudocode | Flowchart |
|---|---|---|
| Format | Text-based | Graphical/visual |
| Best for | Longer, complex algorithms | Shorter algorithms or showing decision logic |
| Ease of writing | Quick to write | Can be time-consuming to draw neatly |
| Exam usage | Very common in Paper 2 | Common for shorter questions |
| Modification | Easy to edit lines | May require redrawing |
Problem: Write an algorithm that asks the user for a password. If the password is correct ("secret123"), display "Access granted". Otherwise, display "Access denied".
OCR Pseudocode:
password = input("Enter password: ")
if password == "secret123" then
print("Access granted")
else
print("Access denied")
endif
Python:
password = input("Enter password: ")
if password == "secret123":
print("Access granted")
else:
print("Access denied")
OCR Exam Tip: Always draw flowchart symbols correctly — use diamonds for decisions (not rectangles), and remember to label the Yes/No branches on decision diamonds. Incorrect symbols will lose marks even if the logic is correct.