Describe and use decomposition

Published by Patrick Mutisya · 14 days ago

Cambridge A-Level Computer Science – 9.1 Computational Thinking Skills: Decomposition

9.1 Computational Thinking Skills – Decomposition

Learning Objective

Describe and use decomposition as a problem‑solving technique.

What is Decomposition?

Decomposition is the process of breaking a complex problem or system into smaller, more manageable sub‑problems or components. Each sub‑problem can be solved independently, and the solutions are then combined to solve the original problem.

Why Decompose?

  • Reduces cognitive load – easier to understand smaller parts.
  • Facilitates teamwork – different people can work on different components.
  • Enables reuse – sub‑solutions can be applied to other problems.
  • Supports testing and debugging – errors can be isolated to a specific component.

Steps for Effective Decomposition

  1. UNDERSTAND THE WHOLE PROBLEM. Identify the overall goal and constraints.
  2. IDENTIFY MAJOR COMPONENTS. Look for natural divisions such as input, processing, and output.
  3. BREAK COMPONENTS INTO SUB‑TASKS. Continue dividing until each sub‑task is simple enough to be expressed as an algorithm or pseudocode.
  4. DEFINE INTERFACES. Specify how sub‑tasks will communicate (inputs, outputs, data structures).
  5. IMPLEMENT AND TEST EACH SUB‑TASK. Verify correctness before moving to the next.
  6. INTEGRATE SUB‑TASKS. Combine the solved parts to form the complete solution.

Example: Calculating the Average of a List of Numbers

Problem: Given a list of \$n\$ numbers, compute the average.

Decomposition:

  1. Read the list of numbers.
  2. Count how many numbers are in the list (\$n\$).
  3. Calculate the sum of the numbers.
  4. Divide the sum by \$n\$ to obtain the average.

Each step can be written as a separate function or sub‑algorithm.

Sample Pseudocode Using Decomposition

function main()

  numbers ← readNumbers()

  total ← sumNumbers(numbers)

  count ← length(numbers)

  avg ← computeAverage(total, count)

  output(avg)

end function

function sumNumbers(list)

  total ← 0

  for each x in list

    total ← total + x

  return total

end function

function computeAverage(total, count)

  return total / count

end function

Decomposition in Real‑World Projects

Project PhaseTypical Decomposition
Requirement AnalysisIdentify functional and non‑functional requirements; split into user stories.
DesignSeparate system into modules (e.g., UI, database, business logic).
ImplementationAssign each module to a developer; write functions/classes.
TestingCreate unit tests for each module; integration tests for combined modules.

Practice Exercise

Decompose the following problem and write a brief outline of the sub‑tasks.

Problem: Design an algorithm that reads a text file, counts how many times each word occurs, and outputs the top three most frequent words.

  • Identify at least four sub‑tasks.
  • State the input and output for each sub‑task.

Suggested diagram: Flowchart showing the decomposition of the “word frequency” problem into sub‑tasks such as “read file”, “tokenise text”, “count words”, “sort frequencies”, and “display top three”.

Key Takeaways

  • Decomposition transforms a large problem into a set of smaller, solvable problems.
  • Clear interfaces between sub‑tasks are essential for successful integration.
  • Effective decomposition improves readability, maintainability, and collaboration.