Skip to content

A4 · Algorithm Design

Spec reference: Section A - Computational Thinking
Key idea: Design a precise, step-by-step strategy to solve a problem.


Introduction to Algorithms


Designing a step-by-step strategy

Algorithm design usually follows this process:

  1. Understand the problem - what are the inputs and outputs?
  2. Decompose - break it into smaller steps.
  3. Identify patterns - are any steps repeated?
  4. Abstract - remove details not needed for the solution.
  5. Write the algorithm - in pseudocode, structured English or a flowchart.
  6. Trace/test - step through the algorithm manually with sample data.
  7. Refine - fix any errors or inefficiencies found.

Properties of a good algorithm

PropertyMeaning
CorrectProduces the right output for all valid inputs
UnambiguousEach step has exactly one interpretation
FiniteIt ends after a fixed number of steps
EfficientIt doesn't use more time or memory than needed
GeneralWorks for the full range of valid inputs, not just one case

Algorithm design example

Problem: Find the largest number in a list.

Step 1: Understand the problem

  • Input: a list of numbers
  • Output: the largest number in that list

Step 2: Design the algorithm

1. Set largest = first element of the list
2. For each remaining element in the list:
   2a. If the element is greater than largest:
       Set largest = that element
3. Output largest

Step 3: Trace with sample data

List: [4, 9, 2, 7, 1]

StepCurrent elementlargest
Start-4
2a9 > 4 → update9
2a2 < 9 → no change9
2a7 < 9 → no change9
2a1 < 9 → no change9
Output-9

Algorithm efficiency

Not all correct algorithms are equally good. Efficiency describes how an algorithm's time or memory use grows as the input gets larger.

TermMeaning
Time complexityHow many steps does the algorithm take?
Space complexityHow much memory does it use?
O(1)Constant - always the same regardless of input size
O(n)Linear - steps grow proportionally with input size
O(n²)Quadratic - steps grow with the square of input size

Exam context

You don't need to calculate Big O formally, but you should understand that an algorithm that loops through a list twice is less efficient than one that loops through it once.


Expressing algorithms

Algorithms can be expressed in three ways - all are valid and each has its place:

MethodWhen to use
Structured EnglishNatural language, easiest to communicate to non-programmers
PseudocodeMore formal, closer to code - best for exam answers
FlowchartsVisual - good for showing decision logic

We cover pseudocode in B1 · Pseudocode and flowcharts in B2 · Flowcharts.


Common mistakes in algorithm design

  • Forgetting edge cases - what if the list is empty? What if two values are equal?
  • Infinite loops - a loop with no exit condition will never terminate.
  • Off-by-one errors - starting at index 1 instead of 0, or looping one iteration too many.
  • Assuming the input is valid - always consider invalid or unexpected input.

Summary

TermMeaning
AlgorithmA finite, ordered set of steps to solve a problem
TraceStepping through an algorithm manually with sample data to verify correctness
EfficiencyHow well an algorithm uses time and memory as input size increases
Edge caseAn unusual or extreme input that might cause an algorithm to fail

Test Yourself

Question 1 of 5

Which of the following is NOT a required property of an algorithm?

Ad

PassMaven - revision made simple.