Ready to begin
No records have been processed. Start with Next step.
After building the two ID lists, we can find their common members without scanning every original field again. For each May ID x, compare it with each Chennai ID y. On equality, append x to the result.
![The common IDs are [3,25], identifying Rida and Geeta. The nested scan compares identifiers, not complete cards.](/images/computational-thinking/week-5/may-chennai.png)
Follow one occurrence at a time. Choose another input to test empty lists, repeated IDs and different parameters.
Ready
No records have been processed. Start with Next step.
Predict the next change, then step through the list. The original course records remain unchanged.
Common = []
foreach x in MayIDs:
foreach y in ChennaiIDs:
if x == y:
Common = Common ++ [x]There are 4 × 8 = 32 equality tests in this complete nested scan. We do not divide by two: these are comparisons across two lists, not unordered pairs within one list. Because each input here has unique IDs, the result contains each common student once.
With duplicates, raw nested matching can repeat results: [3,3] matched with [3,3] appends 3 four times. To implement set-style intersection, require unique inputs or add “if NOT member(Common,x)” before appending. Specify which meaning you want.
Follow one occurrence at a time. Choose another input to test empty lists, repeated IDs and different parameters.
Ready
No records have been processed. Start with Next step.
Predict the next change, then step through the list. The original course records remain unchanged.
MayOnly = []
foreach x in MayIDs:
if NOT member(ChennaiIDs, x):
MayOnly = MayOnly ++ [x]
# [13,23]: Gopi and DeepikaAbsence requires checking the whole other list unless a match is found first. Appending x whenever x != y is wrong: almost every ID differs from some y, including IDs that are also present. Union is another set-like operation: begin with one unique list, then append only members of the other list not already present.
What are May ∩ Chennai and May minus Chennai?
Intersection: [3,25]. May-only: [13,23], in the original May-list order.
Why is IF x != y inside the nested loop not a correct set difference?
A single non-match does not prove x absent. Search all y values and append x only when no match exists.
Can a list intersection reorder the result?
Yes, its sequence depends on the traversal method. Membership may be the same even when output order differs. State the intended convention.