2

Consider a list of bit patterns, each N bits long, and consisting of 0s, 1s, and x's to denote wildcards. For example, for N=8:

0110xx11
1111xx00
111xxxx1
10000000
...

Is there an algorithm for determining whether the list of bit patterns fully covers the range of an integer of N bits in less than O(2^N) time and/or space? Of course the naive approach of simply trying to match every possible value from 0 to 2^N to one of the patterns works but is untenable as the number of bits grows.

I considered something like a trie that goes down both branches (0 and 1) for wildcard entries, but that has a similar problem of consuming tons of memory when there are patterns with many or all wildcard bits.

This feels like something that should be doable in O(N*m) (where m is the number of patterns) time.

Mike
  • 23
  • 2

1 Answers1

1

No, there is no efficient algorithm -- and there is no algorithm faster than exponential time, if we assume the SETH holds.

Your problem is exactly the problem of checking whether a formula in DNF form is a tautology. Each bit pattern corresponds to a DNF clause (0's and 1's are literals). This problem is NP-complete, and assuming SETH, requires exponential time to solve.

However, if you need to solve it in practice, you could use a SAT solver: negate the DNF formula (obtaining a CNF formula), and check whether it is satisfiable.

D.W.
  • 167,959
  • 22
  • 232
  • 500