Data Structures & AlgorithmsVery hardICPC regional · GATE CS

The universe is {1, ..., 8} and the available sets are [[1, 2, 3], [3, 4, 5], [5, 6, 7], [1, 7, 8], [2, 4, 6, 8]]. What is the minimum number of these sets whose union covers the whole universe?

  1. A. 4
  2. B. 5
  3. C. 3
  4. D. 2

Correct answer: C. 3

This is set cover, which is NP-hard in general, so the answer is found by checking subsets (bitmask over the sets). Choosing the set covering the most uncovered elements each time is a fast greedy that can overshoot the optimum.

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

Exams that ask this topic