Cover lesson · Computer Science · Year 7 · Beginner
DCF: Data and computational thinking → Problem-solving and modelling
Name: Class: Date:
Print: this sheet one per pupil, and the stimulus sheet "The six-wire sorting network" one per pair. If you have floor space and chalk or masking tape, copy the shape onto the ground and cut the six number cards out of the stimulus sheet; if not, everything works at the desk with a pencil.
Run: 5 min read the three rules · 10 min walk or finger-trace the network once with the number cards · 15 min complete the trace table on this sheet · 10 min the three "does it always work?" tests · 10 min design a three-wire network and answer the counting questions.
Collect: this sheet. The correct trace table, the three test answers and the three-wire design are all on the worked example sheet, so you can mark it in a couple of minutes.
A sorting network is an algorithm you can walk through. Six numbers go in on the left, and if everybody obeys the same three rules, the numbers always come out in order on the right — without anybody being in charge and without anybody seeing more than two numbers at a time. Your job is to trace the network, test whether it really always works, and then build a smaller one of your own.
Start with 12, 46, 25, 33, 51, 18 on wires 1 to 6. After each step, write what is on each wire. Nothing moves except at a coloured bar.
| After | Wire 1 | Wire 2 | Wire 3 | Wire 4 | Wire 5 | Wire 6 |
|---|---|---|---|---|---|---|
| Start | 12 | 46 | 25 | 33 | 51 | 18 |
| Step 1 — (1,6) (2,4) (3,5) | ||||||
| Step 2 — (2,3) (4,5) | ||||||
| Step 3 — (1,4) (3,6) | ||||||
| Step 4 — (1,2) (3,4) (5,6) | ||||||
| Step 5 — (2,3) (4,5) |
Write out the comparison that surprised you most, and say why:
| Test | What came out, and what that tells you |
|---|---|
| Test 1 — worst case. Put the numbers in backwards: 51, 46, 33, 25, 18, 12. | |
| Test 2 — already sorted. Put them in as 12, 18, 25, 33, 46, 51. How many swaps happen? | |
| Test 3 — repeats. Use 3, 3, 7, 1, 7, 1. Does the rule "the smaller number goes up" still say what to do when both cards are the same? |
Three wires, three numbers. Draw the comparators you need on the grid, then test it with 3 on wire 1, 1 on wire 2 and 2 on wire 3. Write the comparators as pairs underneath, in order.
My comparators, in order: (____,____) (____,____) (____,____) (____,____)
| Question | Your answer |
|---|---|
| 1. How many comparators are there altogether in the six-wire network? | |
| 2. How many steps does it take, if every comparator in a step happens at the same time? | |
| 3. Sorting six cards by comparing every pair would take 6 × 5 ÷ 2 comparisons. How many is that, and how does it compare with your answer to question 1? | |
| 4. What is the smallest number of comparators a three-wire network needs? How do you know two is not enough? |