Quarry School

Reassemble pieces arriving out of order

Subject: Computing
Level 1 · FoundationsAbout 5 min read1 new term
How this was estimated

Programmatic estimate. Rung levels, worked steps, prerequisites, terms and sentence length contribute to this level. It describes the lesson, not your ability.

Reading counts the whole lesson, including folded explanations, at 180 words a minute. Practice allows two minutes per item. These are planning assumptions; take the time you need.

AI estimate unavailable.

Path to here

Open the unit’s lesson list to follow the lesson order.

    Quick review (2 minutes)

    In plain words

    Printed pages that say Page 2 of 11 can be put back in order however the pile was dropped.

    Rule

    The receiver places each usable card in the slot of its piece number when that slot is empty, whatever the order of arrival, and reads the data of slots 1 to N in order once all N slots are filled; an empty slot means no usable card for that piece has arrived yet.

    Step

    1. Check each arriving card against the protocol. Read the total on the first usable data card and lay out that many empty slots.

    2. Put each usable card into the slot of its piece number if that slot is empty; put a card that fails the check aside.

    3. After each card, list the slots still empty.

    4. When no slot is empty, read the data of the slots from 1 to N.

    5. If a slot stays empty, the message is not complete; do not guess its data.

    Trap

    Joining pieces in the order they arrive gives NOONMEET-AT- for the arrivals 3, 1, 2. Place by number.

    Reading the message while a slot is empty gives a message with a hole in it. Wait for every slot; the next lesson shows how the sender sends a missing piece again.

    1 In plain words

    Printed pages that say Page 2 of 11 can be put back in order however the pile was dropped.

    Packets on the internet may arrive in order, out of order, or not at all. They can take different paths: routing is the process of finding a path from sender to receiver, and on the internet it is usually decided as the packets travel, not fixed in advance.

    In the card protocol, the receiver lays out N empty slots, puts each usable card into the slot of its number when that slot is empty (a card for a filled slot is a duplicate, set aside as a later lesson shows), and reads the data of slots 1 to N in order once every slot is filled. A slot still empty means no usable card for that piece has arrived yet.

    Remember one sentence: place each piece by its number, not by when it came. To look it up, see essential knowledge CSN-1.C.2 and CSN-1.C.3 in the AP Computer Science Principles Course and Exam Description.

    2 Picture it

    ArrivedPieceSlots filled1st3 of 332nd1 of 31, 33rd2 of 31, 2, 3

    A table of three cards that arrive out of order. The first to arrive is piece 3 of 3, which fills slot 3. The second is piece 1 of 3, so slots 1 and 3 are filled. The third is piece 2 of 3, and all three slots are filled. The last row is marked.

    Three cards arriving in the order 3, 1, 2, placed by number

    3 Why

    The order of arrival depends on the paths the pieces took, and one path can be faster or shorter than another. In this unit's runs every usable card keeps the number the sender wrote, so the slots put the data back in the order the sender cut it.

    The total on each card tells the receiver how many slots to lay out, so a gap shows. With pieces 1 and 3 of 3 in their slots, slot 2 is empty, and the message is not ready.

    Joining the pieces in arrival order can mix up the message when they arrive out of order. The Field Guide describes TCP, the Transmission Control Protocol used on the internet, putting a sequence number on each packet for this reason; without one, a delayed piece can turn HELLO into HELOL.

    4 The rule

    The receiver places each usable card in the slot of its piece number when that slot is empty, whatever the order of arrival, and reads the data of slots 1 to N in order once all N slots are filled; an empty slot means no usable card for that piece has arrived yet.

    5 How

    1. Check each arriving card against the protocol. Read the total on the first usable data card and lay out that many empty slots.
    2. Put each usable card into the slot of its piece number if that slot is empty; put a card that fails the check aside.
    3. After each card, list the slots still empty.
    4. When no slot is empty, read the data of the slots from 1 to N.
    5. If a slot stays empty, the message is not complete; do not guess its data.

    6 Trace

    Reassemble cards that arrive in the order 3, 1, 2
    Card arrivesSlots 1, 2, 3Empty slotsExplanation
    3 of 3: NOON_, _, NOON1, 2The total says three slots; NOON goes in slot 3.
    1 of 3: MEETMEET, _, NOON2MEET goes in slot 1.
    2 of 3: -AT-MEET, -AT-, NOONnoneEvery slot is filled: the message is MEET-AT-NOON.

    7 The trap

    Joining pieces in the order they arrive gives NOONMEET-AT- for the arrivals 3, 1, 2. Place by number.

    Reading the message while a slot is empty gives a message with a hole in it. Wait for every slot; the next lesson shows how the sender sends a missing piece again.

    Quick checks

    Quick check 1 of 2

    Cards of a 3-piece message arrive in the order 2 of 3 (-AT-), 3 of 3 (NOON), 1 of 3 (MEET). What message does the receiver read, and after which arrival is it complete?

    Show the steps and the answer
    Answer

    It reads MEET-AT-NOON, complete after the third arrival.

    Why: Each card goes into the slot of its number. Slot 1 stays empty until the last card, piece 1, arrives.

    Source: University of Canterbury Computer Science Education Research Group, Computer Science Field Guide: Network Communication Protocols, 16.3 Transport layer protocols - TCP, UDP

    Quick check 2 of 2

    A receiver holds pieces 1, 2 and 4 of a 4-piece message. What does it know, and what can it not do yet?

    Show the steps and the answer
    Answer

    It knows piece 3 is missing, and it cannot read the whole message yet.

    Why: The total says four slots. Slot 3 is empty, so a piece has not arrived, and packets can be lost on the way.

    Source: College Board, AP Computer Science Principles Course and Exam Description

    Sources

    1. Computer Science Field Guide: Network Communication Protocols, 16.3 Transport layer protocols - TCP, UDP. University of Canterbury Computer Science Education Research Group. CC BY-SA 4.0. Read 2 Dec 2026.
    2. AP Computer Science Principles Course and Exam Description. College Board. All rights reserved. Read 2 Dec 2026.