What is the Big O of set intersection, done well?
  • A: O(1)
  • B: O(n)
  • C: O(n log n)
  • D: O(n2)
  • E: O(n3)

    Answer: C

    Set intersection can be done well by sorting both sets, O(n log n), then using the merge technique, O(n), to form the intersection.

    If the sets are subsets of a finite and small set of possibilities, the intersection could be done by an and (&) operation on bit vector representations of the sets, which would be much faster.

    Contents    Page-10    Prev    Next    Page+10    Index