Merging two data sources in pseudocode
Loops through one data source, finds the record with the matching key in the other, then combines them or appends unmatched records, avoiding duplicate keys.
Understanding Merging two data sources in pseudocode in QCE Digital Solutions Unit 3
What it does: Handling records with no match means adding them to the merged result so no data is lost. Checking the key before appending stops the same key appearing twice in the merged result. A merge works by matching on a key field. Loop through one source and search the other for the same key. The key must appear in both sources and identify the same entity. studentId does this; mark does not. Comparing uses a comparison operator such as =. The arrow <- is for assignment, which would overwrite a value instead of testing it. Comparing the key fields (here studentId) is how the merge decides that two records describe the same thing.
Common mistakes: The score must be copied from the matching record in the other source (b.score). Assigning a.score to itself changes nothing, so nothing is merged. It should be a.score <- b.score. The inner loop must search the other data source, listB, for the matching key. Looping through listA again only compares listA with itself. It should be for each b in listB.
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 194–250) and word search (Modules 194–337).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
merge algorithmFill in the Blanks
Spot the Error
Student with a class code? Join your class →