Pattern Masking for Dictionary Matching: Theory and Practice
Authors: Charalampopoulos Panagiotis , Chen Huiping , Christen Peter , Loukides Grigorios , Pisanti Nadia , Pissis Solon P. , Radoszewski Jakub 
Published: March 2024

AbstractData masking is a common technique for sanitizing sensitive data maintained in database systems which is becoming increasingly important in various application areas, such as in record linkage of personal data. This work formalizes the Pattern Masking for Dictionary Matching (PMDM) problem: given a dictionary $$\mathscr {D}$$
D
of d strings, each of length $$\ell $$
ℓ
, a query string q of length $$\ell $$
ℓ
, and a positive integer z, we are asked to compute a smallest set $$K\subseteq \{1,\ldots ,\ell \}$$

K
⊆
{
1
,
…
,
ℓ
}

, so that if q[i] is replaced by a wildcard for all $$i\in K$$

i
∈
K

, then q matches at least z strings from $$\mathscr {D}$$
D
. Solving PMDM allows providing data utility guarantees as opposed to existing approaches. We first show, through a reduction from the well-known k-Clique problem, that a decision version of the PMDM problem is NP-complete, even for binary strings. We thus approach the problem from a more practical perspective. We show a combinatorial $$\mathscr {O}((d\ell )^{|K|/3}+d\ell )$$

O
(

(
d
ℓ
)

|
K
|
/
3

+
d
ℓ
)

-time and $$\mathscr {O}(d\ell )$$

O
(
d
ℓ
)

-space algorithm for PMDM for $$|K|=\mathscr {O}(1)$$

|
K
|
=
O
(
1
)

. In fact, we show that we cannot hope for a faster combinatorial algorithm, unless the combinatorial k-Clique hypothesis fails (Abboud et al. in SIAM J Comput 47:2527–2555, 2018; Lincoln et al., in: 29th ACM-SIAM Symposium on Discrete Algorithms (SODA), 2018). Our combinatorial algorithm, executed with small |K|, is the backbone of a greedy heuristic that we propose. Our experiments on real-world and synthetic datasets show that our heuristic finds nearly-optimal solutions in practice and is also very efficient. We also generalize this algorithm for the problem of masking multiple query strings simultaneously so that every string has at least z matches in $$\mathscr {D}$$
D
. PMDM can be viewed as a generalization of the decision version of the dictionary matching with mismatches problem: by querying a PMDM data structure with string q and $$z=1$$

z
=
1

, one obtains the minimal number of mismatches of q with any string from $$\mathscr {D}$$
D
. The query time or space of all known data structures for the more restricted problem of dictionary matching with at most k mismatches incurs some exponential factor with respect to k. A simple exact algorithm for PMDM runs in time $$\mathscr {O}(2^\ell d)$$

O
(

2
ℓ

d
)

. We present a data structure for PMDM that answers queries over $$\mathscr {D}$$
D
in time $$\mathscr {O}(2^{\ell /2}(2^{\ell /2}+\tau )\ell )$$

O
(

2

ℓ
/
2

(

2

ℓ
/
2

+
τ
)

ℓ
)

and requires space $$\mathscr {O}(2^{\ell }d^2/\tau ^2+2^{\ell /2}d)$$

O
(

2
ℓ

d
2

/

τ
2

+

2

ℓ
/
2

d
)

, for any parameter $$\tau \in [1,d]$$

τ
∈
[
1
,
d
]

. We complement our results by showing a two-way polynomial-time reduction between PMDM and the Minimum Union problem [Chlamtáč et al., ACM-SIAM Symposium on Discrete Algorithms (SODA) 2017]. This gives a polynomial-time $$\mathscr {O}(d^{1/4+\epsilon })$$

O
(

d

1
/
4
+
ϵ

)

-approximation algorithm for PMDM, which is tight under a plausible complexity conjecture. This is an extended version of a paper that was presented at International Symposium on Algorithms and Computation (ISAAC) 2021.