notesonly.in

One notebook for every subject — open it anywhere.

Log in

Difference and Symmetric Difference: Explained with Examples

The difference A minus B keeps the elements that are in A but NOT in B. The symmetric difference, written A delta B, keeps the elements that are in exactly one of the two sets — in A or in B, but not in both.

They matter because real data is full of "what changed" questions. Comparing two lists to find added and removed items is a difference operation, and syncing two copies of data to find everything that differs is a symmetric difference.

Key Concepts

  • Difference A minus B: {x such that x is in A and x is not in B}. Order matters: A minus B is usually different from B minus A.
  • Symmetric difference A delta B: {x such that x is in exactly one of A, B}. Order does NOT matter: A delta B = B delta A.
  • Relation to complement: A minus B = A intersect B', the part of A outside B.
  • Overlap excluded: the symmetric difference deliberately throws away the intersection.

Formulas

  • A minus B = A intersect B'. Equivalently, A minus B = A minus (A intersect B).
  • A delta B = (A minus B) union (B minus A) = (A union B) minus (A intersect B).
  • n(A delta B) = n(A) + n(B) minus 2 times n(A intersect B). The shared elements are removed from both counts.
  • Limits: A minus A = empty set and A delta A = empty set; A delta empty set = A.

Worked Example

Let A = {1, 2, 3, 4, 5} and B = {4, 5, 6, 7}. Find A minus B, B minus A and A delta B.

  1. A minus B: keep members of A that are not in B. 4 and 5 are in B, so remove them, leaving {1, 2, 3}.
  2. B minus A: keep members of B that are not in A. 4 and 5 are in A, so remove them, leaving {6, 7}.
  3. A delta B: elements in exactly one set = {1, 2, 3} union {6, 7} = {1, 2, 3, 6, 7}.
  4. Check the count: n(A) + n(B) minus 2 times n(A intersect B) = 5 + 4 minus 2 times 2 = 5, matching the 5 members found.

Common Misconceptions

  • "A minus B is the same as B minus A." It is not, as the example shows: {1, 2, 3} versus {6, 7}. Only the symmetric difference is order-free.
  • "The symmetric difference includes the common elements." It excludes them by design; "symmetric" refers to treating both sets equally, not to keeping the overlap.
  • "Set difference is like subtraction of numbers." There is no borrowing or negative result; it is simply filtering one list against another.

Real-World Applications

  • Version control: a diff between two file versions shows the symmetric difference of their line sets.
  • Data syncing: comparing a phone's contact list with a backup finds added and deleted contacts.
  • Attendance: enrolled students minus present students gives the absentees.

A minus B filters B out of A, while A delta B keeps everything that belongs to exactly one of the two sets. Remember that difference depends on order and symmetric difference does not, and "what changed" problems solve themselves.