← IGCSE Computer Science Paper 1

Reordering packets at the destination

After the last packet arrives, the receiving device uses the packet numbers in the headers to put the packets in the right order and joins the payloads to rebuild the message.

Understanding Reordering packets at the destination in IGCSE Computer Science Paper 1

What it does: Reordering only happens after the last packet arrives, which the condition checks before calling the reorder step. Joining the payloads in packet-number order recreates the whole message, which is what the plus signs show. Arrival order does not matter. The packets are sorted by their packet numbers once all of them have arrived. The packet number is stored in the header. The header also holds the destination address and the originator's address.

Common mistakes: The packets are only put in order after the last packet has arrived, not as each one arrives. Line 1 should wait until the last packet arrives. The loop should keep storing packets while the last packet has NOT yet arrived. Without NOT, it would not collect the packets properly.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 121–130) and word search (Modules 121–141).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
When does the receiving device put the packets back into the correct order?
Once the last packet has arrivedAs soon as the first packet arrives
Matches
Packets arrive as 3, 1, 2 so the message is rebuilt as 3, 1, 2
↓
The packets were joined in the order they arrived, but they should be reordered by packet number first (1, 2, 3).
Applying
Meanings
Term
reordering packets
Meaning
After the last packet arrives, the receiving device uses the packet numbers in the headers to put the packets in the right order and joins the payloads to rebuild the message.
Practice
WAIT UNTIL last packet has arrived
Testing
Gaps
packets BY packetNumber
Check Answer
Spots
1REORDER as each packet arrives
2READ number from each header

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Blobfish' badge — Pressure Handler, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. When does the receiving device put the packets back into the correct order?
A. As soon as the first packet arrives
B. Once the last packet has arrived ✓
The destination waits until the last packet has arrived, then uses the packet numbers to reorder them.
2. What does the receiving device use to decide the correct order of the packets?
A. The packet numbers in the headers ✓
B. The order in which the packets arrived
Packets can arrive out of order, so arrival order is not reliable. The packet number in each header gives the true order.
3. Packet 3 arrives before packet 2. What happens at the destination?
A. Packet 3 is treated as the second part of the message because it arrived second
B. Packet 3 is kept until all packets arrive, then the packets are sorted by number ✓
Arrival order does not matter. The packets are sorted by their packet numbers once all of them have arrived.
4. After the packets are in the correct order, what is joined together to rebuild the message?
A. The payloads ✓
B. The routers
The payload of each packet holds part of the data. Joining the payloads in order rebuilds the original message.
5. Which statement about reordering packets is correct?
A. The packet number is read from the packet header ✓
B. The packet number is read from the packet trailer
The packet number is stored in the header. The header also holds the destination address and the originator's address.

Match the Pairs

reordering packets → After the last packet arrives, the receiving device puts the packets back into the correct order and rebuilds the message
packet number (in header) → The value the receiving device reads to decide where each packet belongs in the sequence
The receiving device waits until the last packet has arrived before it puts the packets in order → if all_packets_arrived: reorder(packets)
Once the packets are in order, the payloads are joined together to rebuild the original message → message = payload1 + payload2 + payload3
Packets arrive as 3, 1, 2 so the message is rebuilt as 3, 1, 2 → The packets were joined in the order they arrived, but they should be reordered by packet number first (1, 2, 3).
Reorder each packet the moment it arrives, before the last packet → Reordering happens once the last packet has arrived, not while packets are still arriving, because the device cannot sort the full set until it has all of them.

Key Term

reordering packets
After the last packet arrives, the receiving device uses the packet numbers in the headers to put the packets in the right order and joins the payloads to rebuild the message.

Fill in the Blanks

1. IF lastPacketArrived = TRUE THEN SORT packets BY packetNumber ENDIF
Hint: Type the keyword that puts the packets into order once the last packet has arrived.
2. IF lastPacketArrived = TRUE THEN SORT packets BY packetNumber ENDIF
Hint: Type the header field that tells the receiving device the correct order of the packets.
3. WHILE lastPacketArrived = FALSE RECEIVE packet ENDWHILE
Hint: Type the Boolean value that keeps the device receiving packets until the last one has arrived, before reordering begins.
4. FOR EACH packet IN sortedPackets message ← message + packet.payload NEXT packet
Hint: Type the part of a packet that carries the data, which is joined on to rebuild the message.
5. IF packet1.number > packet2.number THEN SWAP packet1, packet2 ENDIF
Hint: Type the comparison operator that checks whether the first packet number is larger than the second, so the packets are out of order.

Spot the Error

Question 1
A REORDER as each packet arrives
B READ number from each header
C SORT packets BY number
D JOIN payloads into message
Line A — The packets are only put in order after the last packet has arrived, not as each one arrives. Line 1 should wait until the last packet arrives.
Question 2
A WHILE lastPacketArrived
B STORE packet
C ENDWHILE
D SORT packets BY packetNumber
Line A — The loop should keep storing packets while the last packet has NOT yet arrived. Without NOT, it would not collect the packets properly.
Question 3
A WAIT for last packet
B SORT packets BY packetNumber
C FOR EACH p IN packets
D ADD p.header TO message
E NEXT p
Line D — The message is rebuilt by joining the payloads, which hold the actual data. The header only holds information such as the packet number. It should be p.payload.
Question 4
A RECEIVE all packets
B READ number from each payload
C SORT packets BY number
D JOIN payloads into message
Line B — The packet number is stored in the packet header, not in the payload. The payload holds the data. It should read the number from each header.
Question 5
A Packets arrive as 2, 3, 1
B Last packet has now arrived
C Sorted order is 2, 3, 1
D Message can now be rebuilt
Line C — Sorting by packet number puts the packets in the order 1, 2, 3. The line 2, 3, 1 is just the order they arrived in.

Student with a class code? Join your class →