Cover lesson · Languages, Literacy and Communication · Year 3 · Beginner

Debugging a library shelving algorithm

DCF: Data and computational thinking → Problem-solving and modelling

Also assessed, LNF: Numeracy → Number system → The number system

Name: Class: Date:

Cover teacher: you need no subject knowledge

What this practises: following, debugging and changing an algorithm (a set of instructions) without a computer. Pupils use a library flowchart to sort 10 returned books, put the non-fiction numbers in order, find 2 bugs and add a new rule. Ordering 3-digit numbers and writing them in words and figures is the numeracy (number system) evidence.

Print: this sheet, one per pupil, in colour if you can. Pupils need a pencil. No computers are needed.

Run: 5 min read “What you are doing” aloud and follow the flowchart together for Book 1 (Rugby skills: it has a number, so it goes on the non-fiction shelf) · 8 min Step 1 · 10 min Step 2 · 7 min Step 3 · 10 min Step 4 · 10 min Step 5 · 7 min Step 6 · 3 min swap and check with a partner. Total 60 minutes.

Collect: this sheet. The numeracy evidence is Step 2 (6 numbers in order with < signs) and Step 5 (numbers in words and figures, and placing new numbers). Answers: Step 2 398 < 523 < 591 < 597 < 796 < 942; Step 4 the swapped books are 597 and 591. The worked example has the rest.

What you are doing

The books in the class library have been returned in a muddle. In many libraries, non-fiction (information) books have a number on the spine, so books about the same subject sit together. Story books have the first 3 letters of the author’s surname instead. Your job is to follow the library’s algorithm, put the books in the right order, and fix the mistakes other people made.

The returned books

796Rugby skillsBook 1DAHThe BFGBook 2523The planetsBook 3942History of WalesBook 4WILThe Story of Tracy BeakerBook 5398Welsh myths and legendsBook 6597Frogs and fishBook 7MORKensuke’s KingdomBook 8591Animals of WalesBook 9DONThe GruffaloBook 10

The library algorithm

Start Pick up the top book from the pile Does it have a numberon the spine? No Yes Story shelf:A to Z by theauthor’s surname Non-fiction shelf:number order, smallestnumber on the left Any more booksin the pile? Yes No Stop

Step 1: follow the flowchart

Follow the flowchart for each book. Tick the shelf it goes on.

BookLabel on the spineStory shelfNon-fiction shelf
1796
2DAH
3523
4942
5WIL
6398
7597
8MOR
9591
10DON

How many books go on each shelf?   Story shelf: ______    Non-fiction shelf: ______

Step 2: put the non-fiction numbers in order

The non-fiction shelf goes from the smallest number on the left to the biggest on the right. Write the 6 numbers in order. Use the < sign, which means “is less than”.

______ < ______ < ______ < ______ < ______ < ______

Which two numbers were the hardest to put in order? Why?

Step 3: put the story books in order

The story shelf goes in A to Z order of the 3 letters. Write the 4 labels in order.

______ ,   ______ ,   ______ ,   ______

Step 4: find the bugs

A bug is a mistake that makes an algorithm go wrong. Debugging means finding the bug and fixing it.

a) Lowri shelved the non-fiction books like this:

398Welsh myths and legends523The planets597Frogs and fish591Animals of Wales796Rugby skills942History of Wales

Which two books are in the wrong order? ______ and ______

b) Gareth wrote the algorithm as a list:

1. Pick up the top book from the pile.
2. Does it have a number on the spine?
3. Yes: put it on the non-fiction shelf in number order. No: put it on the story shelf in A to Z order.
4. Stop.

Gareth followed his algorithm. Only 1 book was put away. What is the bug?

Write a new step 4 to fix it.

Step 5: numbers in words and new books

a) Write these spine numbers in words.

NumberIn words
597
942

b) Write these numbers in figures.

In wordsNumber
seven hundred and ninety-six
three hundred and ninety-eight

c) Three new books arrive. Predict where each one goes on the non-fiction shelf.

New bookIt goes between … and …
Easy cooking, 641
Welsh rugby stars, 796
Dinosaurs, 567

Step 6: change the algorithm

The school wants all books written in Welsh to go on a new shelf: the Cymraeg shelf. Write the new question and the new instruction, and say where they go in the flowchart.

New question
If the answer is yes
It goes after the box

Step by step

  1. 8 min Follow the flowchart and sort the 10 books.
  2. 10 min Put the 6 non-fiction numbers in order.
  3. 7 min Put the 4 story books in A to Z order.
  4. 10 min Find and fix 2 bugs.
  5. 10 min Write numbers in words and figures, and place new books.
  6. 7 min Add a new rule to the algorithm.

Success criteria

If you finish early