Teachers' Portal  /  A-Level Computer Science 9618  /  Algorithm design and problem-solving  /  Abstraction and decomposition
Lesson pack · A-Level Computer Science 9618 · 9.1 · AS Level

Abstraction and decomposition

Think like a programmer. Before any code is written, a programmer has to make a real problem small enough to solve.

Student lesson Lab, full screen
At a glance

The shape of the lesson

Topic
Algorithm design and problem-solving
Syllabus reference
Cambridge International AS and A Level Computer Science 9618, 9.1
Level
AS Level
Duration
45 minutes, lab-led; stretches to a 60 minute block (see the contingency notes)
Position in topic
Lesson 1 of 3 in Algorithm design and problem-solving; leads into Structured English, flowcharts and pseudocode
Central model
Fig. 1: a rail map is an abstract model; real distances, bends and landmarks are removed because a traveller does not need them
Cooperative structure
Assessment
Stage 1 check and the exam-style plenary from the student lesson, plus the worksheet as the exit task
Learning objectives

By the end of the lesson, learners can

Section by section
  • Why we need abstraction: A real system holds far more detail than any program can or should handle.
  • Building an abstract model: In the exam you may be given a scenario and asked to produce an abstract model: list only the details the system needs, often as the data it must store.
  • Decomposition into modules: Decomposition breaks a problem down step by step until each part is small enough to code.
Key points to leave on the board
  • Abstraction: remove details not needed; keep only the essential ones; the result is an abstract model.
  • Benefits: less complex, easier to understand, quicker to design and program, less data, reusable model.
  • Decomposition: break a problem into sub-problems, again and again, until each can be solved.
  • Modules: each sub-problem becomes a procedure (CALLed) or a function (returns a value, used in an expression).
The core visual model

One picture every idea returns to

Abstraction means removing (filtering out) details that are not needed to solve a problem, so that only the essential details remain. The result is an abstract model of the system. It reduces complexity, so the problem is easier to understand, quicker to design and program, and needs less data. Decomposition means breaking a problem into smaller sub-problems, and those into smaller ones, until each is simple enough to solve on its own. Each sub-problem becomes a program module: a procedure or a function.

Abstraction: a rail map keeps only what a traveller needs parkriver 1.8 km2.4 km0.9 km HillMarketBridgeDocks HillMarketBridgeDocks the real system: every detailthe abstract model distances, bends, landmarksstations, order, connections
Fig. 1: a rail map is an abstract model; real distances, bends and landmarks are removed because a traveller does not need them
Lesson sequence

Forty-five minutes, phase by phase

TimePhaseWhat happens in the roomGrouping
0 to 5 minHook: predictOpen with the question in the title, Think like a programmer.. Before any code is written, a programmer has to make a real problem small enough to solve. Put the figure on the board: it is the one picture every idea in the lesson returns to.Whole class, then pairs
5 to 13 minTeach and check: Why we need abstractionA real system holds far more detail than any program can or should handle.Whole class, then pairs
13 to 21 minTeach and check: Building an abstract modelIn the exam you may be given a scenario and asked to produce an abstract model: list only the details the system needs, often as the data it must store. Model the worked example A lift controller on the board, one line at a time. Your turn: A school wants a program to record library loans. Give three details about a book that the program must store, and one detail it should not store.Pairs
21 to 30 minTeach and check: Decomposition into modulesDecomposition breaks a problem down step by step until each part is small enough to code. Project tab 5 of the lab (Procedures and functions as modules) and let a student drive it while the class predicts.Connect-Extend-Challenge
30 to 36 minCheckThe four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong.Individual, then whole class
36 to 43 minPlenaryThe exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording.Individual, random call
43 to 45 minExit and homeworkSet the worksheet below (6 questions, 18 marks). Learners self-assess against the objectives before they leave.Individual
Timing and contingency

Protect the parts that carry the learning

The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.

Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.

Cut first if the build overruns: the last check in Decomposition into modules, never the check or the plenary.

In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.

Running the cooperative task

Connect-Extend-Challenge

After the new idea, each student writes three lines: how it connects to what they knew, how it extends their thinking, and what still challenges them. Pairs compare, then the challenges become the plenary.

The full structure, with its variations and the other twelve, is on the cooperative-learning page.

Examiner traps to pre-empt

What to head off, and how

Trap learners fall intoTeaching move that pre-empts it
Saying abstraction "makes it simpler" is too vague for the mark.Say how: it removes unnecessary details and keeps only the essential ones, so the model is less complex.
An abstract model depends on the purpose.The same book needs its weight in a model for a delivery company but not in a library loans system, so always justify your choices from the scenario.
Do not call a function with CALL.In 9618 pseudocode CALL is only for procedures; a function call is part of an expression, e.g. Letter ← Grade(Mark).
Worksheet

Abstraction and decomposition: worksheet

6 questions, 18 marks. Written in the style of the papers; no past paper question is reproduced.

NameClassDate
Q1 · explain[2 marks]

Describe the purpose of abstraction when designing a solution to a problem.

Q2 · recall[3 marks]

State three benefits of using abstraction.

Q3 · apply[4 marks]

A cinema wants a program to sell seats online. Produce an abstract model of a seat for this program by identifying three essential details. Give one detail that should be left out and justify your choice.

Q4 · explain[2 marks]

Explain how decomposition leads to the use of procedures and functions in a program.

Q5 · analysis[3 marks]

A team is writing a payroll program. Give three advantages of decomposing the program into modules.

Q6 · write[4 marks]

Write pseudocode for a function Larger that takes two integer parameters and returns the larger of the two. Then write a statement that uses the function to output the larger of Score1 and Score2.

Answer key and marking notes
Q1 · 2 marks
  • Removing / filtering out details that are not relevant to the problem.
  • To produce a simplified (abstract) model that keeps only the essential details.
Q2 · 3 marks
  • The problem is less complex / easier to understand.
  • The solution is quicker to design and program (less development time).
  • Less data needs to be collected and stored / the program is smaller; the model may be reused (any one).
Q3 · 4 marks
  • Seat identifier, e.g. row letter and seat number.
  • Whether the seat is booked or available (for the chosen showing).
  • Price band / seat type (e.g. standard, premium, wheelchair space).
  • Left out: e.g. colour of the seat fabric, because it does not affect booking or pricing.
Q4 · 2 marks
  • The problem is broken down into smaller sub-problems (repeatedly).
  • Each sub-problem is small enough to be coded as one module: a procedure or a function.
Q5 · 3 marks
  • Modules can be written by different programmers at the same time.
  • Each module can be tested on its own, so errors are easier to find and fix.
  • Modules can be reused (called many times or in other programs), so code is not repeated; maintenance is easier.
Q6 · 4 marks
  • Header FUNCTION Larger(A : INTEGER, B : INTEGER) RETURNS INTEGER.
  • IF A > B THEN RETURN A ELSE RETURN B ENDIF (or equivalent; either value if equal).
  • ENDFUNCTION.
  • OUTPUT Larger(Score1, Score2) (no CALL, used in an expression).
Quiz

6 multiple-choice questions on this lesson

From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.

Q11 mark

Which statement best describes the purpose of abstraction when designing a solution?

  • ATo remove details that are not needed, giving a simpler model that keeps only the essential ones
  • BTo break the problem into smaller sub-problems that can each be solved separately
  • CTo write the solution as a sequence of numbered steps in structured English
  • DTo add more detail to each step until it can be written as program code
Q21 mark

A program shows parents where their child's school bus is and when it will arrive at each stop. Which detail should be removed from the abstract model of the bus?

  • AThe colour of the seats
  • BThe current position of the bus
  • CThe order of the stops on the route
  • DThe average speed of the bus
Q31 mark

Which is a benefit of decomposing a large program into modules?

  • AEach module can be written and tested separately, possibly by different programmers
  • BThe whole program no longer needs to be tested once the modules work
  • CThe program will need fewer variables because modules cannot declare any
  • DEvery module must return a value, so errors are reported automatically
Q41 mark

What is output by this pseudocode?

FUNCTION Band(Score : INTEGER) RETURNS STRING
    IF Score >= 80 THEN
        RETURN "Gold"
    ELSE
        IF Score >= 60 THEN
            RETURN "Silver"
        ELSE
            RETURN "Bronze"
        ENDIF
    ENDIF
ENDFUNCTION

OUTPUT Band(80) & "-" & Band(60) & "-" & Band(59)

  • AGold-Silver-Bronze
  • BSilver-Bronze-Bronze
  • CGold-Silver-Silver
  • DSilver-Silver-Bronze
Q51 mark

A program contains these two modules:

PROCEDURE ShowTotal(Total : REAL)
FUNCTION AddTax(Price : REAL) RETURNS REAL
Which statement is valid 9618 pseudocode?

  • ACALL ShowTotal(AddTax(20.0))
  • BCALL AddTax(20.0)
  • CCost ← ShowTotal(20.0)
  • DCALL ShowTotal ← AddTax(20.0)
Q61 mark

The weight of a parcel is kept in the abstract model used by a courier's delivery program, but is removed from the abstract model used by a program that sends customers tracking messages. Which statement best explains this?

  • AThe details kept by abstraction depend on the purpose of the program
  • BThe courier's program has not been abstracted, so it keeps every detail
  • CAbstraction always removes numerical data and keeps only text
  • DThe tracking program has been decomposed, so it holds less data
Quiz key
Q1: A

Abstraction filters out unnecessary detail so that only the essential details remain in an abstract model. Breaking a problem into sub-problems is decomposition, writing numbered English steps is structured English, and adding detail level by level is stepwise refinement.

Q2: A

Seat colour has no effect on where the bus is or when it arrives, so abstraction removes it. The current position, the order of stops and the speed are all needed to show the bus and predict arrival times.

Q3: A

Modules are small, self-contained parts that can be shared out across a team and tested on their own, which makes errors easier to find. The complete program must still be tested as a whole. Modules can declare their own local variables, and only functions return a value; procedures do not.

Q4: A

80 >= 80 is TRUE, so Band(80) is Gold. 60 is not >= 80 but is >= 60, so Silver. 59 fails both tests, so Bronze. The three results are joined with & and hyphens: Gold-Silver-Bronze. Silver-Bronze-Bronze treats both tests as strictly greater than, Silver-Silver-Bronze makes that mistake only at 80, and Gold-Silver-Silver treats 59 as reaching the Silver boundary.

Q5: A

A procedure is run with CALL, and its parameter can be any REAL expression, including the value returned by the function AddTax. CALL AddTax(20.0) is wrong because a function is used inside an expression, not CALLed. Cost ← ShowTotal(20.0) is wrong because a procedure returns no value to assign. The last option mixes a CALL with an assignment, which is not valid syntax.

Q6: A

An abstract model keeps only what its own task needs: the courier must plan loads and charges by weight, but a tracking message does not depend on it. The courier's model is still abstracted (it would not hold the colour of the wrapping paper, for example). Abstraction is not about numbers versus text, and decomposition splits a problem into modules rather than removing data.

Lab and demo

What to project

The student lesson embeds these tabs. Open them full screen on the projector; every slider has a drag handle on the stage.

Slides

Slides for this lesson

A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.

Also for this topic

Everything else you can use

Original work by the TheLucidSTEM team. The worksheet items are written in the style of the papers; no past paper question is reproduced.