Robot Bubble Belt
Six robots roll down the conveyor belt in a jumble. The packing door only takes them lightest to heaviest. The belt arm can only look at two neighbors at a time. Teach it to sort the whole line.
๐ง Before we start
Reef Pointer Pairs needed a list that was already sorted. Today we make the sorted list! Bubble sort compares two neighbors, swaps them if the left one is heavier, then steps along the line. After one full sweep, the heaviest robot has bubbled up to the end. Sweep again and again until a whole pass needs no swaps.
Plan one sweep
Tap the arm's steps in the order it should do them for one sweep along the belt.
Swap or keep?
The glowing pair is what the arm sees. Decide for each pair: swap them or keep them. Four pairs.
Sort the whole belt
Run the sweeps yourself. For every glowing pair choose swap or keep. After each pass decide: sweep again, or is the belt sorted?
Predict the sweep
Think like the program. Answer two questions about what a sweep does.
๐ What you learned
- Bubble sort puts a list in order by comparing only two neighbors at a time.
- If the left item is heavier, swap the pair. If not, keep it and step on.
- One full sweep carries the heaviest item to the end of the line.
- Each new sweep fixes one more item at the end, so we repeat passes.
- When a whole pass makes no swaps, the list is sorted and the program can stop.
- Your 6-robot belt took 5 passes and 11 swaps, and bigger belts take many more passes.