Slide 1 of 7 · Settling starter · Computer Science · Year 7
3 minutesUnplugged algorithms: sorting networks
A sorting network is an algorithm you can walk through. 6 numbers go in on the left, and if everybody obeys the same 3 rules, the numbers always come out in order on the right, without anybody being in charge and without anybody seeing more than 2 numbers at a time.
While the register is called: write your name, class and date on your worksheet, then read the 3 rules on the stimulus sheet, The six-wire sorting network.
Starter question: When 2 pupils meet at a coloured bar, which number takes the higher wire?
Slide 2 of 7 · Today’s brief and key words · Computer Science · Year 7
2 minutesYour brief: trace it, test it, then build a smaller one
Step 1: say the 3 rules back to your partner without looking. Today you will fill in a trace table for Card set B, do 3 tests that try to break the network, design a 3-wire network of your own and answer 4 counting questions.
Wire
One of the 6 lines, numbered 1 (top) to 6 (bottom). You only ever move along your own wire, left to right.
Comparator
A coloured bar joining 2 wires. (2,4) means the pupils on wires 2 and 4 compare cards. There are 12 of them.
Step
A group of comparators that all happen at the same time. The network has 5 steps.
Slide 3 of 7 · Step 2: trace the network once · Computer Science · Year 7
10 minutesStep 2: walk or finger-trace the network with Card set B
Put 12, 46, 25, 33, 51, 18 on wires 1 to 6 in that order. Go through the 5 steps using the table of comparators on the stimulus sheet. Nothing moves except at a coloured bar.
| Step | Comparators in that step (all at the same time) |
|---|---|
| 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) |
Slide 4 of 7 · Step 3: the trace table · Computer Science · Year 7
15 minutesStep 3: fill in the trace table, one row per step
After each step, write what is on each wire. Write down every comparison you make, including the ones where nothing moves. Then write out the comparison that surprised you most, and say why.
| 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) | 12 | 33 | 25 | 46 | 51 | 18 |
Slide 5 of 7 · Step 4: does it always work? · Computer Science · Year 7
10 minutesStep 4: 3 tests, each one trying to break the network
Trace each input through all 5 steps and write what came out, and what that tells you.
| Test | Input on wires 1 to 6 |
|---|---|
| Test 1: worst case. Put the numbers in backwards. | 51, 46, 33, 25, 18, 12 |
| Test 2: already sorted. How many swaps happen? | 12, 18, 25, 33, 46, 51 |
| Test 3: repeats. Does “the smaller number goes up” still say what to do when both cards are the same? | 3, 3, 7, 1, 7, 1 |
Slide 6 of 7 · Step 5 and self check · Computer Science · Year 7
7 minutesStep 5: design a 3-wire network, answer the counting questions, then check
Draw the comparators you need on the 3-wire grid, test it with 3 on wire 1, 1 on wire 2 and 2 on wire 3, and write the comparators as pairs underneath in order. Answer the 4 counting questions. Then tick the criteria you have met and correct 1 thing.
- I followed the algorithm exactly as written instead of just sorting the numbers in my head.
- My trace table records the state of all 6 wires after every step, so someone else could check my work.
- I tested the algorithm with awkward inputs: reversed, already sorted, and with repeated values.
- I designed a smaller network of my own and tested it rather than assuming it worked.
- I can explain why doing several comparisons at the same time makes the job finish sooner, even though it does not do fewer comparisons.
Slide 7 of 7 · Plenary review · Computer Science · Year 7
3 minutesQuick-check answers before handing in
Check your main answers before your worksheets are collected.
| Question | Correct answer |
|---|---|
| What comes out when Card set B goes in as 12, 46, 25, 33, 51, 18? | 12, 18, 25, 33, 46, 51 |
| How many comparators, and how many steps, in the 6-wire network? | 12 comparators in 5 steps. |
| How many swaps happen when the numbers go in already sorted? | Zero, but all 12 comparisons still happen. |