Ready to begin
Choose Next step to follow the actual course records.
Find pairs of different students with both the same CityTown and the same Mathematics mark. Checking only city counts too many pairs. Checking only Maths may match students from different cities.

Trace the records, compare the methods and watch what changes. Back and Reset let you try again.
Ready
Choose Next step to follow the actual course records.
Start with Next step. Predict what changes before reading the explanation.
Count = 0
while Table1 has rows:
read first row X
move X from Table1 to Table2
while Table1 has rows:
read first row Y
if X.CityTown == Y.CityTown AND X.Mathematics == Y.Mathematics:
Count = Count + 1
move Y from Table1 to Table3
move all rows from Table3 back to Table1
# Table2 contains the processed outer rows. Count is 1.Moving X out before the inner scan prevents self-comparison. Keeping processed X rows in Table2 prevents reversed duplicate pairs. Table3 holds inner-scan rows temporarily. Return ALL of Table3 to Table1 after each inner scan, or later outer cards will have no partners left to inspect. Here a different order among remaining rows is harmless as long as all remain and each outer row is eventually removed once.
| City | Rows | Pairs |
|---|---|---|
| Ambur | 1 | 0 |
| Bengaluru | 5 | 10 |
| Chennai | 8 | 28 |
| Erode | 2 | 1 |
| Madurai | 5 | 10 |
| Nagercoil | 1 | 0 |
| Salem | 1 | 0 |
| Theni | 1 | 0 |
| Trichy | 3 | 3 |
| Vellore | 3 | 3 |
| Total | 30 | 55 |
After grouping by CityTown, the inner test can be just X.Mathematics == Y.Mathematics because city equality is guaranteed by bin membership. The final answer remains 1. The preparation changes the work, not the matching rule.
Does binning by city mean that every pair within Chennai is a match?
No. City equality is guaranteed, but Maths equality must still be tested.
Why must Table3 be restored after EACH inner scan?
Those rows are still candidates for later outer rows. Without restoring them, the outer loop would stop after inspecting only the first X.
If three students in one city all have the same Maths mark, what does Count gain?
Three pairs, not one city or three separate matches with themselves: A–B, A–C and B–C.