Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

1.1 (2 of 4): Decomposition: break it down

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

45 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

Too big to build all at once

How do you build a whole shopping website? It is too big to build all at once.

But a shop has a few clear jobs. Show the products. Hold a basket. Take a payment. Send an email. You can build each job on its own.

Key words

WordWhat it meansExample
DecompositionBreaking a big problem into smaller parts.a shop: basket, payment, email
FeatureOne thing the system must do or have.search for a product
Block diagramBoxes that show the parts of a system.shop, basket, payment
Information flow diagramA picture that shows what data moves between the parts.order goes to the shop store room
FlowchartA picture of steps, with arrows, in order.start, check stock, end
FunctionA named piece of code that does one job.def item_cost

The cells students fill in are left blank in this preview.

Warm up: break it down

Have a go

Warm up: break it down

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Why break a problem down?

A small part is easier to understand. It is easier to build, and easier to test.

A team can share the parts. One person does the basket. Another does the payment. You can also use a part again in another project.

There is a cost too. The parts must fit together later. Too many tiny parts are hard to look after.

The four tasks of decomposition

TaskWhat you doCinema booking example
1 Find the main featuresList what the system must do.Show films, pick seats, pay, send ticket
2 Describe each featureSay what goes in, what comes out, and what it does.Pick seats: in = film and time. Out = chosen seats.
3 Break the problem downSplit a feature that is still big.Pay: check card, take money, show receipt
4 Break the solution downSplit the plan or the code into small parts.One function for each small job

The cells students fill in are left blank in this preview.

Which task is it?

Have a go

Which task is it?

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Method 1: a block diagram

A block diagram: Cinema booking system at the top breaks into Show films, Pick seats, Pay and Send ticket, and Pay breaks into Check card, Take money and Show receipt.A block diagram: Cinema booking system at the top breaks into Show films, Pick seats, Pay and Send ticket, and Pay breaks into Check card, Take money and Show receipt.

Method 2: an information flow diagram

An information flow diagram, each arrow labelled with the data it carries: Customer to Pick seats, film and seats; Pick seats to Pay, price to pay; Customer to Pay, card details; Pay to Send ticket, payment done; Send ticket to Customer, email with ticket.An information flow diagram, each arrow labelled with the data it carries: Customer to Pick seats, film and seats; Pick seats to Pay, price to pay; Customer to Pay, card details; Pay to Send ticket, payment done; Send ticket to Customer, email with ticket.

A flow diagram shows the data

In a block diagram the top box is the whole problem and each box below is one part. It shows the parts. An information flow diagram shows the data that moves between the parts.

Every arrow has a label. The label says what travels along it.

Your turn: finish the flow diagram

A library lets students borrow books. The diagram has three gaps marked ???.

  1. Replace each ??? with the data that moves along the arrow.
  2. Add one more part, Send reminder.
  3. Join it to the other parts with an arrow that has a label.
flowchart LR
  student([Student]) -->|book name| search[Find the book]
  search -->|??? | loan[Lend the book]
  student -->|library card number| loan
  loan -->|??? | record[Save the loan]
  record -->|??? | student

Make a free account to save your work, or press Start lab to work through the whole lesson.

Method 3: a flowchart

A flowchart: Start, then Pick seats, then the question Seats free?, where yes goes on to Pay and then End, and no goes back to Pick seats.A flowchart: Start, then Pick seats, then the question Seats free?, where yes goes on to Pay and then End, and no goes back to Pick seats.

Method 4: code

Code: python
def pick_seats():
    return "A1, A2"


def pay(seats):
    return "Paid for " + seats


seats = pick_seats()
print(pay(seats))

# Add a function send_ticket and call it.

Make a free account to save your work and track your progress.

Method 5: a written description

You can also write the parts in plain words.

  1. The customer picks a film and seats.
  2. The system shows the price.
  3. The customer pays.
  4. The system emails the ticket.

Writing is quick. But a long text is hard to read quickly.

Match the method to its strength

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Watch: break it down

Press Play on the short film below. It breaks the cinema booking system down with the four tasks, one at a time, into a tree of parts and then into code. Watch how a feature that is still big is split again, and why a list of steps is not the same thing.

Film: decomposition, step by step

Decomposition: break it down

Every scene, as text

  1. Decomposition means breaking a big problem into smaller parts. The whole problem, a cinema booking system, is one box at the top: too big to build all at once. The empty boxes under it are the parts still to find.
  2. Task 1, find the main features: list what the system must do. Show films, Pick seats, Pay and Send ticket each go in a box under the whole problem. Boxes that show the parts make a block diagram.
  3. Task 2, describe each feature: say what goes in, what comes out and what it does. Pick seats takes in the film and time, the customer picks the seats, and out come the chosen seats.
  4. Task 3, break the problem down: split a feature that is still big. Pay becomes Check card, Take money and Show receipt. A small part is easier to build and to test, and two people can build two parts at the same time.
  5. Task 4, break the solution down: one function for each small job. pick_seats() gives back "A1, A2", pay(seats) takes those seats, and print(pay(seats)) prints Paid for A1, A2. The parts must fit together.
  6. Myth (false): decomposition means steps in order. Start, Pick seats, Seats free?, then yes to Pay and End is Method 3's flowchart: it shows the order things happen. Decomposition shows which parts there are. Both are useful, but only one is decomposition.

Your turn: three small functions

A small shop makes a receipt. Break the job into three small functions.

  1. item_cost gives price times quantity.
  2. delivery_charge gives 0 for 20 pounds or more, and 3 for less.
  3. receipt_line gives text like 2 x Cola = 3.0.

Press Run Tests when you finish each one.

Code: python
def item_cost(price, quantity):
    # Cost of one kind of item: price for one, times how many.
    return 0


def delivery_charge(total):
    # Delivery is free for 20 pounds or more. Otherwise it is 3.
    return None


def receipt_line(name, quantity, price):
    # Text like: 2 x Cola = 3.0
    return ""

Make a free account to save your work, or press Start lab to work through the whole lesson.

Key words crossword

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Exit quiz

Have a go

Exit quiz

6 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Remember

Important

Find the features. Describe each one. Break the big ones down. Show it with a block diagram, an information flow diagram, a flowchart, code or words.

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.