Lesson 2: Decomposition and Algorithmic Thinking
AS Level Computer Science
Cambridge International Examination
1 Learning Objectives
By the end of this lesson, you should be able to:
• Apply decomposition to break down complex problems
• Understand and use stepwise refinement
• Create algorithms using structured English
• Develop basic flowcharts to represent algorithms
• Convert between different algorithm representations
2 Decomposition in Computational Thinking
Decomposition is one of the five key strands of computational thinking. It involves
breaking down a complex problem or system into smaller, more manageable parts.
2.1 Benefits of Decomposition
• Makes complex problems more manageable
• Allows different people to work on different parts
• Helps identify specific requirements for each part
• Makes testing and debugging easier
3 Stepwise Refinement
Stepwise refinement is the process of developing an algorithm by starting with a general
description and gradually adding more detail.
1
3.1 Example: Making a Cup of Tea
• Level 1: Make tea
• Level 2: Boil water, get cup, add tea bag, pour water, wait, remove tea bag, add
milk/sugar
• Level 3: For ”boil water”: fill kettle, turn on kettle, wait for boil, etc.
4 Structured English and Pseudocode
Structured English and pseudocode are ways to represent algorithms using a mixture of
natural language and programming constructs.
4.1 Example: Calculating Average
1 BEGIN
2 INPUT three numbers : num1 , num2 , num3
3 total = num1 + num2 + num3
4 average = total / 3
5 OUTPUT average
6 END
4.2 Key Features of Good Pseudocode
• Clear and unambiguous
• Uses programming-like structures without specific syntax
• Includes keywords like INPUT, OUTPUT, IF, THEN, ELSE, WHILE, FOR
• Shows sequence, selection, and iteration clearly
5 Flowcharts
Flowcharts are visual representations of algorithms using standardized symbols.
5.1 Basic Flowchart Symbols
• Oval: Start/End
• Rectangle: Process
• Diamond: Decision
• Parallelogram: Input/Output
• Arrows: Flow direction
2
5.2 Example: Login Process Flowchart
Start → Enter username and password → Validate → If valid: grant access → If invalid:
show error → End
6 Past Paper Practice
6.1 Cambridge AS Level Past Paper Question (2021)
”A vending machine sells drinks for $1.50 each. The machine accepts only $1 and $0.50
coins. Write an algorithm in pseudocode to:”
1. Calculate the amount of money inserted by a customer
2. Determine if enough money has been inserted
3. Calculate and output the change if necessary
7 Homework Assignment
Design an algorithm for a library book borrowing system. Include:
1. A decomposition of the problem into sub-problems
2. Structured English description of the main process
3. Pseudocode for the book return process
4. A flowchart showing the book search process
8 Exit Ticket Questions
1. Define decomposition in your own words.
2. What is the purpose of stepwise refinement?
3. Convert this structured English to pseudocode: ”If the student’s score is greater
than or equal to 80, output ’A grade’. Otherwise, output ’B grade’.”