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
UNDERSTAND THE WHOLE PROBLEM. Identify the overall goal and constraints.
IDENTIFY MAJOR COMPONENTS. Look for natural divisions such as input, processing, and output.
BREAK COMPONENTS INTO SUB‑TASKS. Continue dividing until each sub‑task is simple enough to be expressed as an algorithm or pseudocode.
DEFINE INTERFACES. Specify how sub‑tasks will communicate (inputs, outputs, data structures).
IMPLEMENT AND TEST EACH SUB‑TASK. Verify correctness before moving to the next.
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:
Read the list of numbers.
Count how many numbers are in the list (\$n\$).
Calculate the sum of the numbers.
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 Phase
Typical Decomposition
Requirement Analysis
Identify functional and non‑functional requirements; split into user stories.
Design
Separate system into modules (e.g., UI, database, business logic).
Implementation
Assign each module to a developer; write functions/classes.
Testing
Create 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.