Minimum number of 1s in the binary representation of XOR of a number and a number chosen from the set

Viewed 52

I'm looking for a suitable data structure that supports two operations:

  1. Adding a number to a set.
  2. Querying the minimum number of 1s in the binary representation of a given number X xor {a number from the set}.

I have thought about using a segment tree since we have updates and queries but can't figure out how to do that. I also tried to implement a trie solution but it basically had exponential complexity.

I need a structure that supports this minimum query in logarithmic complexity.

Any tips would be appreciated. Thank you! :)

0 Answers
Related