I have a list of sorted arrays ("sets") of integers $A_1..A_n$ where each element is unique w.r.t. the other elements in the same array:
- $A_i = \{x_{i,1}..x_{i,c_i}\}$
- $x_{i,p} < x_{i,p+1}$
$A_i$ has length $c_i$ and the average of $c_i \ll n$. For example in one of the runs, the average $c_i$ ranged from $10$ to $15$ and $n$ from $2000$ to $15000$.
I want to find all combinations of four different arrays $M=\{A_r,A_s,A_t,A_u\}$, where each element that appears in any of the $A$'s, appears in at least one of the other $A$'s:
$\forall A_i \in M: \forall x \in A_i: \exists A_{j \ne i} \in M: x \in A_j$
Assuming that only a small number of the combinations $\epsilon \ll n (\ll O(n^4))$ satisifies these requirements, is there a way to do this more efficiently than the obvious $O(n^4f(c))$? Here $f(c)$ is some reasonably small function in the average $c_i$.
It's probably viable for me if it can be done in $O(n^2c)$ but not if it's $O(n^3c)$.
If we consider the problem described so far to be the case with $|M|=4$, is there also an efficient algorithm for the case with $|M|=3$?
For the case with $|M|=2$, I can simply add each $A_i$ to a hash set after checking if another $A_j$ with the same values is already in the hash set, with expected time about $O(nc)$.
I'm also very interested in the cases where there's up to $y$ cases of $x_i$ that appear in only one of the sets of $M$, where $y = y'-|M|$ and $y'$ is $4$ or $5$
So where would I use such an algorithm? I'm writing a SAT solver. The idea of the solver is that it looks for an integer solution to an ILP problem (without inequality constraints). I have a rectangular matrix with very small integers (0,1,2 mod 3, without the n=2m constraint and the promise) and bring it into Smith normal form. To reduce the search search space, I look for a small set of rows with a small number of nonzero entries, but such rows could be hidden as linear combinations of the rows in the matrix. However since the matrix is in Smith normal form, a row with 4 nonzero entries can only be a linear combination of up to 4 rows, as any 5 rows have 5 pivots. Each row of the normal-form matrix becomes an $A_i$ in the described problem, with the pivot column removed.
The current implementation on github (first link above) only finds rows with 2 nonzero entries and it takes $O(n^2)$ in the worst case.