Data Structures & AlgorithmsVery hard

Among pairs with A[i] ≠ A[j] and A[i] XOR A[j] = 0, how many exist?

  1. A. All pairs with odd values.
  2. B. None, because XOR is zero exactly when the two values are equal.
  3. C. Every pair of distinct values.
  4. D. Exactly one pair.

Correct answer: B. None, because XOR is zero exactly when the two values are equal.

XOR of two values is zero exactly when they are identical bit by bit, i.e. equal. So no pair of distinct values has XOR zero.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic