Write algorithms using pseudocode or flowcharts
Algorithm Design & Problem Solving
What is an Algorithm?
An algorithm is a step‑by‑step recipe for solving a problem. Think of it like a cooking recipe: you list ingredients (data), steps (operations), and the final dish (output).
Key properties:
- Finite – must finish after a finite number of steps.
- Unambiguous – each step is clear and precise.
- Effective – uses only basic operations that can be performed by a computer.
- Input & Output – accepts data and produces a result.
Pseudocode vs Flowcharts
Pseudocode is a human‑readable description of the algorithm, written in plain language or a mix of code and comments. It’s flexible and easy to write.
Flowcharts use shapes to represent operations (ovals for start/end, rectangles for processes, diamonds for decisions). They’re visual and great for brainstorming.
Both are useful for the IGCSE exam – you may be asked to write either.
Designing an Algorithm: Step‑by‑Step
- Understand the problem – read carefully, identify inputs, outputs, and constraints.
- Plan a solution – think of a high‑level approach (e.g., “sort the list then sum the first three”).
- Break into steps – write each operation clearly.
- Write pseudocode – use
IF,FOR,WHILE, etc. - Check for edge cases – empty lists, negative numbers, etc.
- Test the algorithm – run through sample data mentally or on paper.
Example: Find the Largest Number in a List
Suppose we have a list of integers and we need to find the maximum.
MAX ← first element of list
FOR each element x in list
IF x > MAX
MAX ← x
RETURN MAX
Flowchart representation:
- Start → Initialize MAX → For each element → Decision: x > MAX?
- If yes, update MAX; then continue loop.
- After loop, output MAX → End.
Complexity Basics
Algorithms are often analysed by their time complexity, expressed using Big‑O notation.
Examples:
- $O(1)$ – constant time (e.g., accessing an array element).
- $O(n)$ – linear time (e.g., a single loop over n items).
- $O(n^2)$ – quadratic time (e.g., nested loops over n items).
- $O(\log n)$ – logarithmic time (e.g., binary search).
In exams, you might be asked to state the complexity of a given algorithm.
Exam Tips Box
- Read the question twice to catch all details.
- Use clear variable names (e.g.,
sum,maxValue). - Show all steps – even trivial ones, to avoid missing marks.
- When writing pseudocode, keep it language‑agnostic (avoid syntax of a specific language).
- For flowcharts, use the correct shapes and label decisions clearly.
- Check for edge cases (empty input, single element, negative numbers).
- Time complexity: identify loops and nested loops; remember that a single loop over n items is $O(n)$.
Practice Problem
Write a pseudocode algorithm that takes a list of integers and returns the sum of the two largest distinct numbers.
Hint: Think about sorting or scanning twice.
Try it on paper before checking the answer.
Revision
Log in to practice.