Introduction
Think about making a cup of tea. You boil the water, place the tea bag in the cup, pour the water, wait a moment, remove the bag, and add milk if you like. You follow those steps in a specific order every time. That sequence of instructions is — in its simplest form — an algorithm.
An algorithm is a finite, ordered set of well-defined instructions designed to solve a problem or complete a task. Every step is clear, the process has a definite end, and it produces a result. Algorithms are the foundation of computer science, programming, and logical problem-solving, and understanding them is essential for any student studying computing, coding, or mathematics.
Key Takeaways
-
An algorithm is a precise, step-by-step set of instructions for solving a problem.
-
Every algorithm must be finite, clear, and produce at least one output.
-
Algorithms are used in everyday life, mathematics, and computer science.
-
They can be represented as written steps, pseudocode, or flowcharts.
-
Different algorithms can solve the same problem in different ways.
-
A good algorithm is correct, clear, efficient, and general.
-
Sorting and searching are among the most important types of algorithms in computing.
What Is an Algorithm?
An algorithm is a precise, step-by-step set of instructions that describes how to solve a problem or perform a task.
The word algorithm comes from the name of the 9th-century Persian mathematician Muhammad ibn Musa al-Khwarizmi. His written works, translated into Latin, introduced systematic methods for arithmetic and problem-solving to the Western world. His name, Latinised as “Algoritmi,” gave us the word we use today.
Every algorithm has five key characteristics:
- Input — It accepts zero or more inputs.
- Output — It produces at least one output or result.
- Definiteness — Each step is clearly and precisely defined with no ambiguity.
- Finiteness — It must terminate after a finite number of steps.
- Effectiveness — Each step must be simple enough to be carried out exactly.
Consider this algorithm for baking a cake:
- Preheat the oven to 180°C.
- Mix flour, sugar, eggs, and butter in a bowl.
- Pour the mixture into a baking tin.
- Place the tin in the oven and bake for 30 minutes.
- Remove the tin and allow the cake to cool.
This qualifies as an algorithm because it is ordered, finite, unambiguous, and produces a clear output — a baked cake.
Why Are Algorithms Important?
Algorithms are the building blocks of every computer program ever written. Without them, computers would have no way to process information or solve problems.
Every time you search for something online, get walking directions, or withdraw money from an ATM, an algorithm is running behind the scenes. Understanding how algorithms work helps you think logically, break complex problems into manageable parts, and make better decisions when writing code.
Here are four everyday examples of algorithms at work:
- Search engine results — algorithms rank billions of pages to show you the most relevant result first.
- GPS navigation — algorithms calculate the shortest or fastest route to your destination.
- ATM cash withdrawal — a sequence of steps verifies your identity, checks your balance, and dispenses the correct amount.
- Social media feeds — algorithms decide which content to show you and in what order.
Properties of a Good Algorithm
Not every set of instructions counts as a good algorithm. Here is what separates a well-designed algorithm from a poor one.
Correctness
A correct algorithm produces the right output for every valid input. If it works for some inputs but fails for others, it is not correct.
For example, an algorithm that finds the maximum of two numbers must work correctly when both numbers are positive, both are negative, and when they are equal.
Clarity
Each step must be completely unambiguous. The person or machine following the algorithm must know exactly what to do at every point — no guessing allowed.
Finiteness
Every algorithm must stop. A set of instructions that runs forever is not an algorithm — it is an infinite loop. For instance, an algorithm that keeps asking a user for input without ever moving forward has no finiteness.
Efficiency
A good algorithm completes the task using as few steps and as little memory as possible. An efficient algorithm matters enormously when processing large amounts of data.
Generality
A good algorithm works for a wide range of inputs, not just one specific case. An algorithm that finds the largest of exactly three numbers is less general than one that finds the largest of any list of numbers.
How to Write an Algorithm
Algorithms can be written in three main ways: natural language steps, pseudocode, and flowcharts.
1. Written Steps — Natural Language
This is the most straightforward approach. You write out the instructions in plain English.
Example: Finding the largest of two numbers.
- Step 1: Start.
- Step 2: Input two numbers, A and B.
- Step 3: If A is greater than B, output A.
- Step 4: Otherwise, output B.
- Step 5: End.
This is readable and easy to understand, though it can become imprecise for complex problems.
2. Pseudocode
Pseudocode is a structured but informal way of writing an algorithm. It looks like programming code but does not follow the exact rules of any specific language. It is a planning tool used before writing real code.
Example: Finding the largest of two numbers.
BEGIN
INPUT A, B
IF A > B THEN
OUTPUT A
ELSE
OUTPUT B
END IF
END
Pseudocode makes it easy to translate your logic into any programming language once the design is done.
3. Flowcharts
A flowchart is a visual diagram that represents the steps of an algorithm using standardised shapes connected by arrows.
| Symbol | Shape | Meaning |
|---|---|---|
| Start / End | Oval | Marks the beginning or end of the algorithm |
| Process | Rectangle | An action or instruction to be carried out |
| Decision | Diamond | A yes/no question that creates a branch |
| Input / Output | Parallelogram | Data entering or leaving the algorithm |
| Arrow | Line with arrowhead | Shows the direction of flow |
Flowchart description — Finding the largest of two numbers:
Start → Input A and B → Decision: Is A > B? → Yes: Output A → End. No: Output B → End.
Flowcharts are particularly useful for visualising decision points and loops. They make the logic of an algorithm easy to follow at a glance.
Types of Algorithms
Algorithms are grouped into types based on the kind of problem they solve and the approach they use.
Sorting Algorithms
Sorting algorithms arrange a list of items into a specific order — usually ascending or descending. Sorting is one of the most common operations in computing.
Algorithms that work on sorted or structured data rely on efficient organisation of information. Understanding how data is structured is equally important — read [What Is a Data Structure?] for a clear explanation.
Common sorting algorithms:
- Bubble Sort — Compares neighbouring items and swaps them if they are in the wrong order. Repeats until no swaps are needed.
- Selection Sort — Finds the smallest item in the unsorted portion and places it at the front.
- Merge Sort — Repeatedly divides the list in half, sorts each half, then merges the sorted halves together.
Bubble Sort — Worked Trace:
Sort the list: [5, 3, 8, 1]
Pass 1:
- Compare 5 and 3 → swap → [3, 5, 8, 1]
- Compare 5 and 8 → no swap → [3, 5, 8, 1]
- Compare 8 and 1 → swap → [3, 5, 1, 8]
Pass 2:
- Compare 3 and 5 → no swap
- Compare 5 and 1 → swap → [3, 1, 5, 8]
- Compare 5 and 8 → no swap
Pass 3:
- Compare 3 and 1 → swap → [1, 3, 5, 8]
- Compare 3 and 5 → no swap
Sorted result: [1, 3, 5, 8]
Searching Algorithms
Searching algorithms locate a specific item within a dataset.
Linear Search — Checks each item from the beginning, one at a time, until the target is found or the list ends. Works on unsorted lists.
Binary Search — Works only on sorted lists. Repeatedly divides the list in half, eliminating one half based on whether the target is larger or smaller than the midpoint.
Binary Search — Worked Trace:
Find 7 in the sorted list: [1, 3, 5, 7, 9, 11]
- Step 1: Left index = 0, Right index = 5. Middle index = (0 + 5) / 2 = 2. Value at index 2 = 5.
- 5 < 7, so search the right half: [7, 9, 11] (indices 3–5).
- Step 2: Left = 3, Right = 5. Middle = (3 + 5) / 2 = 4. Value at index 4 = 9.
- 9 > 7, so search the left half: index 3 only.
- Step 3: Value at index 3 = 7. Match found.
Result: 7 is found at index 3.
Recursive Algorithms
A recursive algorithm is one that calls itself to solve a smaller version of the same problem. Every recursive algorithm needs:
- A base case — the condition where the recursion stops.
- A recursive case — where the function calls itself with a smaller input.
Example: Factorial of 4
4! = 4 × 3!
3! = 3 × 2!
2! = 2 × 1!
1! = 1 ← base case
Working back up:
- 2! = 2 × 1 = 2
- 3! = 3 × 2 = 6
- 4! = 4 × 6 = 24
Brute Force Algorithms
A brute force algorithm tries every possible solution until it finds the correct one. It is simple to implement but often impractical for large inputs.
Example: Cracking a 4-digit PIN by trying all combinations from 0000 to 9999. There are 10,000 possible combinations, and the algorithm tries each one until a match is found.
Divide and Conquer Algorithms
These algorithms divide a large problem into smaller subproblems, solve each independently, and combine the results.
Example: Merge Sort divides a list in half repeatedly, sorts each half, and merges them back together.
Greedy Algorithms
A greedy algorithm always makes the locally optimal choice at each step, hoping this leads to the best overall solution.
Example: Making 27p with the fewest coins.
- Start with the largest coin that fits: 20p.
- Remaining: 7p. Next largest that fits: 5p.
- Remaining: 2p. Use: 2p.
Result: 20p + 5p + 2p = 3 coins.
Dynamic Programming
Dynamic programming solves complex problems by breaking them into overlapping subproblems and storing the results of each subproblem to avoid repeated calculations. It is used in shortest-path algorithms and optimisation problems and is more advanced than most approaches covered at GCSE level.
Algorithm Complexity — Big O Notation
When comparing two algorithms that solve the same problem, efficiency matters. We measure efficiency by asking: how does the number of steps grow as the input size increases?
Big O notation provides a standard way to describe this growth.
| Big O | Name | Example Algorithm |
|---|---|---|
| O(1) | Constant | Accessing an array element by index |
| O(log n) | Logarithmic | Binary Search |
| O(n) | Linear | Linear Search |
| O(n²) | Quadratic | Bubble Sort |
- O(1) means the algorithm takes the same number of steps no matter how large the input.
- O(n) means if the input doubles, the steps double.
- O(n²) means if the input doubles, the steps quadruple.
- O(log n) means each step eliminates half the remaining possibilities, so the algorithm scales very well.
A lower Big O generally means a more efficient algorithm for large inputs.
Algorithms in Real Life
Search Engines
Search engines use sophisticated ranking algorithms to evaluate billions of web pages and return the most relevant results in under a second. Factors such as keywords, page authority, and user behaviour all feed into the algorithm.
GPS and Navigation
Navigation applications use shortest-path algorithms — such as Dijkstra’s algorithm — to calculate the fastest or shortest route between two points, accounting for traffic, road speed, and distance.
Streaming Services
Recommendation systems analyse your viewing or listening history and apply algorithms to predict which content you are most likely to enjoy next.
Banking and Finance
Banks use pattern-recognition algorithms to detect unusual transaction behaviour in real time. If your card is used in two countries within minutes, an algorithm flags the transaction for review.
Healthcare
Medical software uses diagnostic algorithms to help identify conditions, interpret scan results, and model how infectious diseases spread through a population.
Algorithms in Mathematics
Long before computers existed, mathematicians were writing algorithms for solving problems systematically.
The Euclidean Algorithm finds the greatest common divisor (GCD) of two numbers and is one of the oldest known algorithms, dating back over 2,000 years.
Find GCD of 48 and 18:
- Step 1: 48 ÷ 18 = 2, remainder 12
- Step 2: 18 ÷ 12 = 1, remainder 6
- Step 3: 12 ÷ 6 = 2, remainder 0
GCD = 6
When the remainder reaches 0, the divisor at that step is the GCD. This algorithm is finite, correct, and efficient.
Other mathematical algorithms include:
- Long division — a step-by-step method for dividing large numbers.
- Sieve of Eratosthenes — a method for finding all prime numbers up to a given limit.
Pseudocode Examples
Understanding how variables and loops work in pseudocode is important.
Example 1: Finding the Largest Number in a List
Problem: Find the largest number in a list of five numbers.
BEGIN
INPUT list[1..5]
SET max = list[1]
FOR i = 2 TO 5
IF list[i] > max THEN
SET max = list[i]
END IF
END FOR
OUTPUT max
END
Explanation: The algorithm starts by assuming the first item is the largest. It then compares each remaining item in turn. If a larger item is found, it becomes the new maximum. After checking all items, the maximum is output.
Example 2: Sum of Numbers 1 to n
Problem: Calculate the sum of all integers from 1 to n.
BEGIN
INPUT n
SET total = 0
FOR i = 1 TO n
SET total = total + i
END FOR
OUTPUT total
END
Explanation: The variable total starts at zero. The loop adds each integer from 1 to n. Loops in pseudocode work in the same way as loops in real programming languages
Example 3: Even or Odd Check
Problem: Determine whether a number is even or odd.
BEGIN
INPUT number
IF number MOD 2 = 0 THEN
OUTPUT "Even"
ELSE
OUTPUT "Odd"
END IF
END
Explanation: MOD gives the remainder after division. If a number divided by 2 leaves a remainder of 0, it is even. Otherwise, it is odd.
Example 4: Count Down from n to 1
Problem: Count down from a given number n to 1.
BEGIN
INPUT n
WHILE n >= 1
OUTPUT n
SET n = n - 1
END WHILE
END
Explanation: The algorithm outputs n, then reduces it by 1, and repeats until n is less than 1.
Example 5: Simple Login System
Problem: Allow access only if the correct password is entered.
BEGIN
INPUT password
IF password = "secure123" THEN
OUTPUT "Access granted"
ELSE
OUTPUT "Access denied"
END IF
END
Explanation: The algorithm compares the entered password to the stored one. If they match, access is granted. Otherwise, it is denied.
Algorithms vs Programs
Students sometimes use these two words interchangeably. They are related, but they are not the same thing.
| Feature | Algorithm | Program |
|---|---|---|
| Definition | Step-by-step plan for solving a problem | An algorithm written in a specific programming language |
| Language used | Natural language or pseudocode | Python, Java, C++, and others |
| Language dependency | Independent of any language | Depends entirely on the chosen language |
| Purpose | Design and planning | Implementation and execution |
| Can run on a computer | No | Yes |
An algorithm is the plan. A program is how that plan is built and executed on a computer. For more on programming languages and how they implement algorithms, read [What Is a Programming Language?]
Common Mistakes Students Make When Studying Algorithms
| Incorrect Approach | Correct Approach |
|---|---|
| Treating an algorithm and a program as the same thing | An algorithm is language-independent; a program uses a specific language |
| Writing a loop with no exit condition | Every algorithm must terminate — always include an exit condition |
| Forgetting the base case in a recursive algorithm | Recursion without a base case runs forever — always define when to stop |
| Writing ambiguous steps like “process the data” | Each step must be specific and actionable |
| Using binary search on an unsorted list | Binary search only works on sorted data |
| Testing only one input value | Test your algorithm with a range of inputs including edge cases |
| Skipping steps when tracing through an algorithm | Show every comparison and swap — examiners award marks for each step |
| Assuming a lower step count always means better | Efficiency is about how performance scales with input size, not just total steps |
Algorithm Cheat Sheet
| Concept | Description | Example |
|---|---|---|
| Algorithm | Ordered set of steps to solve a problem | Recipe for baking a cake |
| Pseudocode | Informal structured code plan | IF x > y THEN OUTPUT x |
| Flowchart | Visual diagram using standard shapes | Oval → Rectangle → Diamond |
| Linear Search | Checks each item one by one | Find a name in an unsorted list |
| Binary Search | Divides a sorted list in half repeatedly | Find a number in a sorted list |
| Bubble Sort | Compares and swaps adjacent items | Sort [5, 3, 8, 1] into order |
| Recursion | A function that calls itself | Factorial calculation |
| Greedy Algorithm | Makes the locally best choice at each step | Coin change with fewest coins |
| Divide and Conquer | Split the problem, solve each part, combine | Merge Sort |
| Big O Notation | Describes how efficiency scales with input size | O(n), O(log n), O(n²) |
Worked Examples
Example 1: Real-World Algorithm
Problem: Write an algorithm for withdrawing cash from an ATM.
Steps:
- Insert card.
- Enter PIN.
- If PIN is correct, proceed. Otherwise, display error and end.
- Select withdrawal amount.
- If balance is sufficient, dispense cash and update balance.
- Otherwise, display “Insufficient funds.”
- Return card and end.
Explanation: Each step is clear, finite, and produces a defined result.
Example 2: Pseudocode — Simple Decision
Problem: Output whether a temperature is hot or cold.
BEGIN
INPUT temp
IF temp > 25 THEN
OUTPUT "Hot"
ELSE
OUTPUT "Cold"
END IF
END
Example 3: Pseudocode — Loop
Problem: Output numbers from 1 to 5.
BEGIN
FOR i = 1 TO 5
OUTPUT i
END FOR
END
Example 4: Identifying Algorithm Properties
Problem: Is this an algorithm? “Keep adding 1 to x.”
Answer: No. It has no termination condition and no output. It is not finite.
Example 5: Bubble Sort Trace
Problem: Sort [4, 2, 6, 1].
Pass 1: [2, 4, 1, 6]
Pass 2: [2, 1, 4, 6]
Pass 3: [1, 2, 4, 6]
Sorted: [1, 2, 4, 6]
Example 6: Linear Search Trace
Problem: Find 6 in [2, 5, 6, 9, 11].
Check index 0: 2 ≠ 6.
Check index 1: 5 ≠ 6.
Check index 2: 6 = 6. Found at index 2.
Example 7: Binary Search Trace
Problem: Find 9 in [1, 3, 7, 9, 13, 15].
- Middle = index 2, value = 7. 7 < 9, search right: [9, 13, 15].
- Middle = index 4, value = 13. 13 > 9, search left: [9].
- Index 3, value = 9. Found at index 3.
Example 8: Recursive Algorithm
Problem: Write a recursive algorithm for 5!
5! = 5 × 4! = 5 × 24 = 120
Base case: 1! = 1. Recursive case: n! = n × (n-1)!
Example 9: Identifying the Base Case
Problem: In the factorial algorithm, what is the base case?
Answer: The base case is when n = 1, because 1! = 1 and no further recursion is needed.
Example 10: Euclidean Algorithm
Problem: Find GCD of 56 and 21.
- 56 ÷ 21 = 2 remainder 14
- 21 ÷ 14 = 1 remainder 7
- 14 ÷ 7 = 2 remainder 0
GCD = 7
Example 11: Flowchart Description
Problem: Describe a flowchart for checking if a number is positive.
Start → Input number → Is number > 0? → Yes: Output “Positive” → End. No: Output “Not positive” → End.
Example 12: Identifying a Greedy Algorithm
Problem: Is selecting the largest coin first when making change a greedy approach?
Answer: Yes. At each step, the largest available coin that does not exceed the remaining amount is chosen.
Example 13: Classifying Algorithm Type
Problem: Classify Binary Search by type.
Answer: Divide and conquer — it divides the list in half at each step.
Example 14: Identifying a Correct Algorithm
Problem: Does this algorithm correctly find the minimum of two numbers?
IF A < B THEN OUTPUT A ELSE OUTPUT B
Answer: Yes. It correctly outputs the smaller of A and B for all valid inputs.
Example 15: Identifying an Incorrect Algorithm
Problem: Is this a valid algorithm? “WHILE x > 0, SET x = x + 1, OUTPUT x.”
Answer: No. x increases with each iteration, so the condition x > 0 is always true. The algorithm never terminates.
Example 16: Evaluating Algorithm Efficiency
Problem: Which is more efficient for large datasets — Linear Search or Binary Search?
Answer: Binary Search is more efficient. Linear Search is O(n), while Binary Search is O(log n). For 1,000,000 items, Binary Search needs roughly 20 comparisons; Linear Search may need up to 1,000,000.
Example 17: Comparing Linear and Binary Search
| Feature | Linear Search | Binary Search |
|---|---|---|
| Requires sorted data | No | Yes |
| Worst case | O(n) | O(log n) |
| Best for | Unsorted, small lists | Sorted, large lists |
Example 18: Applying Big O
Problem: What is the Big O of an algorithm that checks every pair in a list of n items?
Answer: O(n²) — for each of the n items, it compares against n others.
Example 19: Converting Natural Language to Pseudocode
Natural language: “If a student scores 50 or above, output Pass. Otherwise, output Fail.”
BEGIN
INPUT score
IF score >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
END IF
END
Example 20: Real-World Algorithm Analysis
Problem: Describe the algorithm a streaming service uses to recommend content.
Steps:
- Record the user’s viewing history.
- Compare the history with other users who watched similar content.
- Identify content those users watched that the current user has not seen.
- Rank those titles by similarity score.
- Output the top-ranked titles as recommendations.
Type: This is a form of collaborative filtering — a searching and ranking algorithm applied to user data.
Practice Questions
20 Multiple Choice Questions
Question 1: What is an algorithm?
A. A programming language
B. A set of ordered, finite instructions for solving a problem
C. A type of computer hardware
D. A piece of software
Correct Answer: B
Explanation: An algorithm is a precise, finite, and ordered set of steps for solving a problem. It is not tied to any language or hardware.
Question 2: Which of the following is NOT a property of a good algorithm?
A. Finiteness
B. Ambiguity
C. Correctness
D. Efficiency
Correct Answer: B
Explanation: Ambiguity is the opposite of what a good algorithm needs. Every step must be clear and unambiguous.
Question 3: What does Big O notation measure?
A. The number of variables in a program
B. How algorithm efficiency scales with input size
C. The size of a file
D. The speed of a processor
Correct Answer: B
Explanation: Big O notation describes how the number of steps in an algorithm grows as the input size increases.
Question 4: What is the Big O of Binary Search?
A. O(1)
B. O(n)
C. O(log n)
D. O(n²)
Correct Answer: C
Explanation: Binary Search is O(log n) because each step eliminates half of the remaining possibilities.
Question 5: Which sorting algorithm compares adjacent elements and swaps them?
A. Merge Sort
B. Binary Search
C. Selection Sort
D. Bubble Sort
Correct Answer: D
Explanation: Bubble Sort repeatedly compares neighbouring elements and swaps them if they are in the wrong order.
Question 6: Which searching algorithm requires sorted data to function correctly?
A. Linear Search
B. Brute Force Search
C. Binary Search
D. Sequential Search
Correct Answer: C
Explanation: Binary Search divides the list in half based on comparisons, which only works correctly on sorted data.
Question 7: What shape represents a decision in a flowchart?
A. Rectangle
B. Oval
C. Parallelogram
D. Diamond
Correct Answer: D
Explanation: A diamond shape represents a yes/no decision point in a standard flowchart.
Question 8: What is the base case in a recursive algorithm?
A. The step where the algorithm loops
B. The stopping condition that ends the recursion
C. The first input value
D. The final output
Correct Answer: B
Explanation: The base case defines when recursion stops. Without it, the algorithm would loop forever.
Question 9: What is pseudocode?
A. A programming language for beginners
B. Code that has errors in it
C. An informal structured way of describing an algorithm
D. A type of flowchart
Correct Answer: C
Explanation: Pseudocode is an informal, structured way of writing an algorithm that resembles code but follows no specific language rules.
Question 10: What is the Big O of Bubble Sort?
A. O(1)
B. O(log n)
C. O(n)
D. O(n²)
Correct Answer: D
Explanation: In the worst case, Bubble Sort compares every pair of elements, giving quadratic time complexity.
Question 11: Which algorithm always makes the locally best choice at each step?
A. Divide and conquer
B. Dynamic programming
C. Greedy algorithm
D. Recursive algorithm
Correct Answer: C
Explanation: Greedy algorithms make the best available choice at each step without reconsidering past decisions.
Question 12: What does O(1) mean?
A. The algorithm takes one step
B. The algorithm never completes
C. Performance is constant regardless of input size
D. The algorithm has one input
Correct Answer: C
Explanation: O(1) means the number of steps does not change as the input size grows.
Question 13: What is the key difference between an algorithm and a program?
A. Programs are longer than algorithms
B. Algorithms are written in Python; programs are not
C. An algorithm is a plan; a program is its implementation in a specific language
D. Programs do not require algorithms
Correct Answer: C
Explanation: An algorithm describes what to do in language-independent terms. A program implements the algorithm in a specific programming language.
Question 14: Which of the following is a divide-and-conquer algorithm?
A. Bubble Sort
B. Linear Search
C. Merge Sort
D. Greedy coin change
Correct Answer: C
Explanation: Merge Sort repeatedly divides the list, sorts each half, then merges them — a classic divide-and-conquer approach.
Question 15: What does the oval shape represent in a flowchart?
A. A decision
B. An input or output
C. A process step
D. Start or End
Correct Answer: D
Explanation: An oval marks the start or end point of a flowchart.
Question 16: What is the output of this pseudocode when n = 3? FOR i = 1 TO n: OUTPUT i
A. 1 2 3
B. 3 2 1
C. 0 1 2 3
D. 1 2
Correct Answer: A
Explanation: The loop runs from i = 1 to i = 3, outputting each value: 1, 2, 3.
Question 17: Which property ensures an algorithm produces a result?
A. Finiteness
B. Generality
C. Output
D. Clarity
Correct Answer: C
Explanation: The output property states that an algorithm must produce at least one result.
Question 18: What is the GCD of 36 and 12 using the Euclidean Algorithm?
A. 6
B. 9
C. 12
D. 4
Correct Answer: C
Explanation: 36 ÷ 12 = 3 remainder 0. The GCD is 12.
Question 19: A linear search checks 1,000 items. In the worst case, how many comparisons are made?
A. 10
B. 500
C. 1,000
D. 1,000,000
Correct Answer: C
Explanation: Linear Search checks each item one by one. In the worst case, it checks all n items, giving O(n).
Question 20: Which real-world system uses a shortest-path algorithm?
A. A spell-checker
B. A GPS navigation app
C. A word processor
D. A photo editor
Correct Answer: B
Explanation: GPS navigation apps use shortest-path algorithms such as Dijkstra’s to find the best route.
10 Short Answer Questions
Q1: Write a simple algorithm for making a phone call.
Model Answer:
- Unlock the phone.
- Open the contacts application.
- Search for the contact’s name.
- Tap the call button.
- Wait for the call to connect.
- End the call when finished.
Q2: Trace Bubble Sort on [7, 2, 5, 4]. Show every step.
Model Answer:
- Pass 1: [2, 7, 4, 5] → [2, 4, 5, 7]
- Pass 2: [2, 4, 5, 7] — no swaps needed.
- Sorted: [2, 4, 5, 7]
Q3: Use binary search to find 14 in [2, 6, 10, 14, 18, 22].
Model Answer:
- Middle = index 2, value = 10. 10 < 14, search right.
- Middle = index 4, value = 18. 18 > 14, search left.
- Index 3, value = 14. Found at index 3.
Q4: Identify the type of algorithm used when breaking a list in half repeatedly.
Model Answer: Divide and conquer.
Q5: What is wrong with this algorithm? “WHILE x ≠ 0, SET x = x + 2.”
Model Answer: If x starts as an odd number, it will never equal 0. The algorithm never terminates.
Q6: Write pseudocode to find the sum of all even numbers from 1 to 20.
Model Answer:
BEGIN
SET total = 0
FOR i = 1 TO 20
IF i MOD 2 = 0 THEN
SET total = total + i
END IF
END FOR
OUTPUT total
END
Q7: Why is binary search faster than linear search for large datasets?
Model Answer: Binary search is O(log n), eliminating half the data at each step. Linear search is O(n), checking every item. For large n, O(log n) requires far fewer comparisons.
Q8: What are the two essential components of a recursive algorithm?
Model Answer: A base case (the stopping condition) and a recursive case (where the function calls itself with a smaller input).
Q9: Use the Euclidean Algorithm to find the GCD of 72 and 48.
Model Answer:
- 72 ÷ 48 = 1 remainder 24
- 48 ÷ 24 = 2 remainder 0
- GCD = 24
Q10: Name two real-world applications of algorithms and explain how they use them.
Model Answer: GPS navigation uses shortest-path algorithms to calculate the fastest route. Banking fraud detection uses pattern-recognition algorithms to flag unusual transactions.
5 Challenge Problems
Challenge 1: Write pseudocode for a number-guessing game.
BEGIN
SET secret = 42
SET guessed = FALSE
WHILE guessed = FALSE
INPUT guess
IF guess = secret THEN
OUTPUT "Correct!"
SET guessed = TRUE
ELSE IF guess < secret THEN
OUTPUT "Too low"
ELSE
OUTPUT "Too high"
END IF
END WHILE
END
Challenge 2: Trace Bubble Sort on [9, 3, 7, 1, 5]. Show all passes.
Pass 1: [3, 7, 1, 5, 9]
Pass 2: [3, 1, 5, 7, 9]
Pass 3: [1, 3, 5, 7, 9]
Pass 4: No swaps — sorted.
Sorted: [1, 3, 5, 7, 9]
Challenge 3: Compare Linear Search and Binary Search for finding 15 in [3, 7, 11, 15, 19, 23, 27].
Linear Search: Check index 0 (3), 1 (7), 2 (11), 3 (15) — found after 4 comparisons.
Binary Search: Middle = index 3, value = 15 — found in 1 comparison.
Binary Search is significantly faster here, and the advantage grows with larger lists.
Challenge 4: Identify three errors in this algorithm.
BEGIN
INPUT x
WHILE x > 0
SET x = x + 1
OUTPUT x
END
Errors:
- The loop has no termination — x increases and never reaches 0.
- The OUTPUT statement is outside the loop but the loop never ends.
- There is no END WHILE statement, making the structure invalid.
Challenge 5: Design an algorithm for a simple library book return system.
BEGIN
INPUT book_id
INPUT return_date
LOOK UP due_date FROM book_id
IF return_date <= due_date THEN
OUTPUT "Returned on time. No fine."
ELSE
SET days_late = return_date - due_date
SET fine = days_late × 0.20
OUTPUT "Late return. Fine: £" + fine
END IF
MARK book_id AS available
END
Explanation: The algorithm looks up the due date, calculates any fine if the return is late, and marks the book as available.
Exam Tips
- Read the problem carefully before writing a single step of your algorithm.
- Make sure every algorithm has a clearly defined start and end.
- Write pseudocode consistently — use the same formatting and keywords throughout.
- When writing recursive algorithms, always include the base case first.
- Trace through your algorithm manually with a test value before submitting.
- Label every shape in a flowchart correctly using the standard symbols.
- Always state that binary search requires sorted data if the question involves searching.
- When asked about efficiency, use Big O notation and explain what it means.
- Test edge cases — what happens when the input is 0, negative, or very large?
- In tracing questions, show every comparison and every swap — do not skip steps.
Quick Revision Notes
What is an algorithm? A finite, ordered, and precise set of instructions that solves a problem or completes a task.
Properties: Input, Output, Definiteness, Finiteness, Effectiveness, Correctness, Efficiency, Generality.
How to write one: Natural language steps, pseudocode, or flowcharts.
Pseudocode: Informal, structured planning tool that resembles code but is language-independent.
Flowchart symbols: Oval (Start/End), Rectangle (Process), Diamond (Decision), Parallelogram (Input/Output), Arrow (Flow).
Sorting algorithms: Bubble Sort O(n²), Selection Sort O(n²), Merge Sort O(n log n).
Searching algorithms: Linear Search O(n), Binary Search O(log n) — requires sorted data.
Recursion: A function calling itself. Must have a base case and a recursive case.
Greedy algorithms: Take the locally best option at each step.
Divide and conquer: Split the problem, solve each part, combine the results.
Big O notation: O(1) constant, O(log n) logarithmic, O(n) linear, O(n²) quadratic.
Real-life uses: Search engines, GPS, banking, streaming, healthcare.
Algorithm vs program: An algorithm is the plan. A program is the implementation.
Frequently Asked Questions
1. What is an algorithm in simple terms?
An algorithm is a step-by-step set of instructions for solving a problem or completing a task. Think of it as a recipe — a finite, ordered guide that produces a specific result.
2. Where does the word algorithm come from?
It comes from the name of the 9th-century Persian mathematician Muhammad ibn Musa al-Khwarizmi, whose works on systematic problem-solving were translated into Latin as “Algoritmi.”
3. What are the properties of a good algorithm?
A good algorithm is correct, clear, finite, efficient, and general. It accepts inputs, produces an output, and terminates after a defined number of steps.
4. What is pseudocode?
Pseudocode is a structured but informal way of writing an algorithm using language that resembles code. It is used for planning before writing in a real programming language.
5. What is a flowchart?
A flowchart is a visual diagram that uses standardised shapes — ovals, rectangles, diamonds, and parallelograms — to represent the steps of an algorithm.
6. What is the difference between an algorithm and a program?
An algorithm is a language-independent plan. A program is that plan implemented in a specific programming language such as Python or Java.
7. What is a sorting algorithm?
A sorting algorithm arranges a list of items into a defined order. Common examples include Bubble Sort, Selection Sort, and Merge Sort.
8. What is a searching algorithm?
A searching algorithm locates a specific item in a dataset. Linear Search checks each item one by one. Binary Search divides a sorted list in half repeatedly.
9. What is recursion in algorithms?
Recursion is when an algorithm calls itself to solve a smaller version of the same problem. It requires a base case to stop the recursion.
10. What is Big O notation?
Big O notation describes how the number of steps in an algorithm grows as the input size increases. Common examples are O(n) for linear growth and O(log n) for logarithmic growth.
11. What is the difference between linear search and binary search?
Linear search checks every item in order and works on unsorted data. Binary search divides the list in half and requires sorted data. Binary search is significantly faster for large datasets.
12. What is a greedy algorithm?
A greedy algorithm makes the locally optimal choice at each step. It is simple and fast but does not always produce the globally optimal result.
13. How are algorithms used in everyday life?
Algorithms power search engines, navigation apps, banking systems, streaming recommendations, and healthcare diagnostics.
14. What makes one algorithm better than another?
An algorithm is better if it produces correct results for all valid inputs, terminates in fewer steps, and scales well as input size increases (measured by Big O notation).
15. Do I need to know algorithms for GCSE computer science?
Yes. GCSE and IGCSE computer science specifications require students to understand, write, trace, and evaluate algorithms using pseudocode and flowcharts.
Summary
An algorithm is a precise, finite, and ordered set of instructions that solves a problem or completes a task. Algorithms must be correct, clear, finite, efficient, and general.
They can be represented as written steps, pseudocode, or flowcharts. The main types include sorting algorithms, searching algorithms, recursive algorithms, greedy algorithms, and divide-and-conquer algorithms.
Algorithm efficiency is measured using Big O notation, where O(1) is the most efficient and O(n²) is typical of simpler sorting methods like Bubble Sort.
Algorithms are used in search engines, GPS, banking, streaming, healthcare, and mathematics. They are the plan behind every program ever written.
Final Thoughts
Understanding what is an algorithm is one of the most important steps any computing student can take. Algorithms underpin everything in computer science — from the simplest school project to the most complex software system.
Mastering algorithms helps you write better code, solve problems more clearly, and think more logically in every subject. The skills you develop — breaking problems into steps, testing your solutions, and evaluating efficiency — are valuable far beyond the classroom.
Work through the examples, practise tracing algorithms by hand, and apply what you learn to real problems. These skills will stay with you throughout your education and your career.
References
- Khan Academy — Algorithms
- BBC Bitesize — Algorithms
- MIT OpenCourseWare — Introduction to Algorithms
- CS50 Harvard — Introduction to Computer Science
- Encyclopaedia Britannica — Algorithm
- Wolfram MathWorld — Algorithm
Disclaimer:
This article is intended for educational and informational purposes only. While LearnMinto strives to provide accurate and up-to-date computer science information, readers should verify important academic concepts through official textbooks, educational institutions, examination boards, or trusted educational resources before using this content for exams or academic purposes. LearnMinto is not affiliated with any specific school, university, research institution, or examination board.