I'm working with some code that needs a large (constant) bit array. Since it contains large constant spans (all 0's or all 1's) I've broken it into a two-level table that allows duplicate spans (constant or otherwise) to be elided, as in:
bitn = table2[table1[n/256]+n%256/8]&1<<n%8
At this point, entries of table1
are all multiples of 32 (256 bits), but I wonder if significant savings could be achieved by allowing the spans in table2
to overlap. So my question is (stated in the abstract form):
Given N strings { S_n : n=1..N } each of length K, is there an efficient way to find the shortest length string S such that each S_n is a substring of S?
(Note that since I probably want to keep my bit arrays 8-bit aligned, my particular application of the problem will probably be dealing with strings of 8-bit bytes rather than strings of bits, but the problem makes sense on any sense of character - bit, byte, or whatever.)