Data Structures & AlgorithmsVery hardICPC regional · meet in the middle

Problem: For a set of 40 items split into two halves of 20, the meet-in-the-middle approach solves subset-sum queries in roughly which time?

  1. A. 2^40, about 10^12 operations
  2. B. 40^2, about 1600 operations
  3. C. 40!, which is infeasible
  4. D. 2^20 * log, about 2 * 10^7 operations

Correct answer: D. 2^20 * log, about 2 * 10^7 operations

Each half has 2^20 subset sums, and sorting plus binary search (or a hash set) processes them in about 2^20 log operations. Enumerating all 2^40 subsets directly is the trap.

More Coding Interview Problems questions

Exams that ask this topic