A Bitwise Approach to SCER Matching in Indeterminate Strings
Abstract
We study the problem of matching a determinate pattern against an indeterminate text of the same length , where each text position is a set of possible characters drawn from an alphabet of size . We study this matching problem under the order-preserving and parameterized matching setting. For that, we encode character sets by bit expressions using sum-free sequences. This encoding enables constant-time character comparisons and avoids explicit set operations. We present an optimal time algorithm for order-preserving matching and an time algorithm for parameterized matching, where and denote the number of distinct parameterized symbols in the pattern and the text, respectively. The proposed techniques significantly reduce overhead while maintaining exactness, offering practical performance improvements for pattern matching under uncertainty. Additionally, we extend the parameterized matching framework to allow mismatches, for which we present an algorithm with time complexity .
Keywords and phrases:
string matching, indeterminate strings, SCER matchingFunding:
Dominik Köppl: JSPS KAKENHI Grant Number 25K21150.Copyright and License:
2012 ACM Subject Classification:
Information systems Information retrievalSupplementary Material:
Software (Source Code): https://github.com/marfra99x/SCER-ISM [7]archived at
swh:1:dir:c33fa1f2fdf35f4030601b03c54ad27d5931dfd0
Editors:
Philip Bille and Nicola PrezzaSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
The problem of string matching is a foundational challenge in theoretical computer science, with widespread applications in areas such as bioinformatics, text retrieval, and pattern recognition [5, 12]. In its classical formulation, the problem assumes deterministic input, where each position in a string contains a single, fixed character drawn from a finite alphabet. Under this assumption, a match between two strings is defined as exact equality at every position.
However, in many real-world scenarios, this assumption does not hold. Strings may exhibit uncertainty – so-called indeterminate strings – in which some positions contain a set of possible characters rather than a unique one. This type of uncertainty naturally arises in biological sequence analysis (e.g., ambiguous nucleotides), noisy or corrupted text data, and symbolic pattern recognition, motivating the need for more expressive and robust matching models [19].
A standard approach to matching indeterminate strings is to interpret a match as the existence of a consistent assignment of characters to each position such that the two strings become identical. When the alphabet is small, an efficient implementation strategy is to encode characters and character classes using bit-parallelism. In this setting, the alphabet is mapped to a set of bit masks, and each symbol is represented as a binary vector indicating the presence or absence of characters. For instance, in the DNA alphabet , each character can be encoded using a 4-bit mask, and indeterminate symbols correspond to bitwise combinations of these masks. This representation allows character comparisons to be performed using constant-time bitwise operations, making it highly effective in practice [17].
An alternative encoding strategy is based on number-theoretic techniques, where each character is associated with a distinct prime number and indeterminate symbols are represented as products of primes. Matching can then be tested via greatest common divisor (GCD) computations. While conceptually elegant, this approach is generally impractical due to the high computational cost of arithmetic operations and the exponential growth of prime products, restricting its applicability to very small alphabets [6].
Beyond exact matching, indeterminate string matching has been studied under more general equivalence relations that capture richer notions of similarity. A particularly important class is that of substring consistent equivalence relations (SCERs). An equivalence relation is said to be substring consistent if, for any two strings and such that , it holds that (i) , and (ii) for all substrings. This property ensures that matching is preserved under substring extraction and is satisfied by several well-known matching paradigms.
Notable examples of SCER-based matching include parameterized matching, order-preserving matching, and variants of palindrome pattern matching. These models have been widely studied due to their applicability in domains where structural or relative relationships between symbols are more important than their exact identities.
1.1 Related Work
Efficient algorithms for string matching over indeterminate strings have been extensively studied. A widely used technique for small alphabets is bit-parallel encoding, where characters and character classes are represented as bit masks. This approach enables constant-time set operations and has been successfully applied in practical domains such as bioinformatics and text processing [17].
Alternative encoding methods based on prime numbers have also been proposed. In this framework, each character is assigned a distinct prime number, and indeterminate symbols are represented as products of primes. Matching is then reduced to testing divisibility via GCD computations. Although mathematically appealing, this approach suffers from significant practical limitations due to the cost of arithmetic operations and the rapid growth of encoded values [6].
The study of indeterminate string matching under equivalence relations has led to the development of the SCER framework. Several important string matching paradigms fall within this class, including parameterized matching [2, 10], order-preserving matching [13, 9], and palindrome-related matching problems [15].
Henriques et al. [13] introduced the first SCER-based approach to indeterminate string matching by investigating the order-preserving pattern matching problem. They showed that an indeterminate pattern of length can be matched against a determinate string in time, where is the maximum number of symbols per indeterminate position, by exploiting structural properties of the value domains.
More recently, Gawrychowski et al. [11] studied the problem of matching two indeterminate strings under SCERs. They presented the first polynomial-time algorithm for the Cartesian tree variant of the problem, achieving deterministic time and expected time, using space, for constant .
Furthermore, they established the NP-hardness of the order-preserving variant for , resolving an open question, and showed that the parameterized version is NP-hard for . Since both problems reduce to classical string matching when , these results provide a complete complexity classification for these SCER-based matching problems.
1.2 Our Contribution
In this work, we focus on the problem of matching a determinate pattern string against an indeterminate text string , both of length , under SCER-based matching models. In particular, we study both order-preserving and parameterized matching, and further extend the latter to support mismatches.
Our contributions can be summarized as follows:
-
We present an -time algorithm for order-preserving matching between a determinate pattern and an indeterminate text.
-
We establish that our approach admits an efficient parallelization, analyzing its work and span in the PRAM model, while leaving practical aspects for future investigation.
-
We develop an algorithm for parameterized matching with running time where and denote the number of distinct parameterized symbols in the pattern and text, respectively.
-
We extend the parameterized matching framework to support mismatches, providing an efficient solution in the indeterminate setting.
The remainder of the paper is organized as follows. In Section 2, we introduce the necessary definitions and notation. Section 3 presents our linear-time algorithm for order-preserving matching. Section 4 describes our parameterized matching algorithm, while Section 5 extends it to support mismatches. Section 6 presents our experimental results. Finally, Section 7 concludes the paper and outlines directions for future work.
2 Preliminaries
This section introduces the notation, definitions, and mathematical foundations required for our approach. We begin by defining indeterminate strings and their matching criteria, followed by an introduction to sum-free sequences (an increasing sequence of numbers is sum-free if no term can be expressed as the sum of any subset of its preceding terms ; e.g., the powers of two ) and their computational properties, which form the basis for our efficient encoding and search mechanisms.
Let be a finite and totally ordered alphabet. A determinate string of length is defined as: An indeterminate string of length is a string whose symbols are taken from the power set of , that is Since each position can be a singleton set, indeterminate strings are a generalization of determinate strings.
We define assignment of an indeterminate string is a string such that .
For an indeterminate symbol , we denote its elements in increasing order as Equivalently, each element can be characterized as so in particular is the minimum of . This notation allows us to explicitly refer to the -th element of .
This perspective also highlights a connection with 2D-strings [3], since each position of an indeterminate string can be regarded as a (sorted) list of possible symbols.
A common technique for handling indeterminate strings is to use a bitwise encoding, where each character position is represented by a bitmask indicating which symbols are present [18]. This allows set operations, such as membership testing, to be performed efficiently. Specifically, each symbol is assigned a unique bit position, and the presence of a set of characters at a given position is represented as a bitwise OR operation over their corresponding bit values. Let be an alphabet of size . We define a mapping that assigns a distinct power of two to each symbol: , similarly given a determinate string we define . Then, an indeterminate letter is encoded by the mapping as: , i.e. the -th bit is set to if and only if the -th symbol of is contained in . Likewise, we can generalize to strings. Using this encoding, a match between an indeterminate text and an indeterminate pattern at position can be determined using a bitwise AND operation: This formulation allows for fast comparisons and eliminates the need for explicit set intersection checks.
We define the symbol to denote the bitwise AND operation between two binary strings of equal length. Given , the result of is the binary string such that for all .
Throughout this work, we assume the standard word-RAM model with word size . Under this assumption, bitwise operations on machine words can be performed in constant time when the alphabet size is bounded by . For larger alphabets, an additional factor is required to account for set operations.
2.1 Order Preserving Pattern Matching
Two strings and of the same length over are said to be order-equivalent, written , if for all pairs of positions on the strings. For example, which shows in particular that their central value is the largest in both strings.
The order preserving pattern matching (OPPM) problem is naturally defined as follows: given a pattern and a text , find all the substrings of that are order-equivalent to . For example, occurs equivalently at position on but nowhere else. For instance, it does not appear at position because , while in the pattern the corresponding values satisfy .
Given a determinate string of length , an indeterminate string of equal length is said to be order-preserving with respect to , denoted , if there exists a determinate assignment of such that the relative orders of the symbols in and coincide, that is,
2.2 Parameterized Pattern Matching
Parameterized pattern matching is a SCER-based model in which symbols from a parameterized alphabet may be dynamically renamed to match symbols in a text, as long as symbolic consistency is preserved. Let , where contains fixed symbols and contains parameterized ones. Given a pattern and a text , a parameterized match occurs if there exists a bijective mapping where and denote the subsets of parameterized symbols that actually appear in and , respectively. The mapping must preserve equality: if two positions in contain the same parameter symbol, then their mapped counterparts in must also be equal – and vice versa. Fixed symbols from must match exactly, without transformation.
Example 1.
Let the fixed alphabet be and the parameterized alphabet be . Consider the pattern and the text , both of length . A parameterized match occurs under the bijective mapping , where fixed symbols a and b match exactly, and the repeated parameter symbol X is consistently mapped to Y. Since the mapping is bijective, it preserves the symbolic structure of , and the transformed pattern equals , so the match is valid.
Given a determinate pattern of length , an indeterminate text of equal length is said to parameterized-match if there exists a determinate assignment of and a bijective mapping such that:
-
for all positions , if , then ;
-
for all positions such that , we have
3 Order-Preserving Matching in Indeterminate Strings
Let and be two strings of equal length, drawn from a finite ordered alphabet of size . Each symbol is assigned a unique numerical value through the mapping: This encoding ensures that each determinate character is represented as a distinct power of two.
For an indeterminate string , given the presence of indeterminate positions , where a character may belong to a subset of , the numerical representation is given by:
This representation ensures that determinate characters correspond to single powers of two, while indeterminate positions are encoded as sums of distinct powers of two. Since the powers of two form a sum-free sequence, each distinct subset of characters maps to a unique integer representation. This property allows for efficient encoding and comparison of indeterminate positions using bitwise operations. Thus, in this model, the string is determinate, which means that each position contains exactly one character, while is indeterminate, allowing each position to contain a subset of characters from .
An order-preserving match occurs when the text matches , such that the relative order of the characters in is preserved in . This formulation enables pattern matching in settings where the uncertainty in must be taken into account while maintaining structural consistency.
Indeterminate OPPM
Input: A determinate pattern and an indeterminate text of length , where each .
Output: true if there exists an assignment of such that order-preserving matches ; false otherwise.
To formalize this notion, we define a rank function that assigns an order-preserving rank to each character of a string. A ranking is order-preserving if the ranked string order-preserving matches with the original string. The rank function is defined as defines a permutation, whose inverse gives the indices of in increasing order with respect to their ranks.
Since preserves order relations, determining an order-preserving match in our setting reduces to verifying whether the ranks of the positions is the same, for some assignment of . The algorithm processes the text according to the order induced by the rank vector of the pattern . For each position in this order, it checks whether is determinate or indeterminate.
Lemma 2.
A positive integer is a power of two if and only if the following bitwise condition holds:
Proof.
Suppose is a power of two. Then there exists an integer such that . The binary representation of consists of a single bit set at position , with all lower bits set to : Subtracting results in a number where all bits below position are set to , and the bit at position is set to : Computing the bitwise AND operation, we obtain: Thus, the condition holds for all powers of two.
Conversely, suppose is not a power of two. Then, in its binary representation, contains at least two bits set to . The binary representation of follows from the standard property that subtracting from a number in binary flips all trailing s to s and the rightmost to . Consequently, at least one bit set in remains set in , ensuring that the bitwise AND operation satisfies: Thus, the given condition is violated for all non-powers of two.
Since we have proven both directions, the statement follows.
Example 3.
Consider the numbers and and their binary representations:
Applying the bitwise AND operation: Thus, the condition holds, confirming that is a power of two. Applying the bitwise AND operation: Since the result is nonzero, the condition fails, confirming that is not a power of two.
If is determinate, it must respect the order constraints, which means that it should be greater than or equal to the previously selected value. If is indeterminate, a greedy selection strategy is used to extract the smallest valid value that is at least as large as the previous selection.
In order to formalize the greedy procedure, we define a sequence of selected values. Suppose the positions from have already been processed. Then the algorithm has chosen values according to the following procedure: set (because ), and for each we set such that .
The element is called the selected value at step . At step , the algorithm checks that contains at least one candidate greater than or equal to the selected value .
Lemma 4.
Given a previously selected value , the operation removes all values in that are smaller than , where is the two complement representation of .
Proof.
In binary representation, the two’s complement of is given by where represents the bitwise negation of . This transformation results in a binary number in which all bits up to and including the least significant of remain , while all higher bits are set to .
Performing the bitwise AND operation between and ensures that any bits in that correspond to positions below the least significant in are set to , while bits at positions equal to or higher than remain unchanged. Consequently, all values in smaller than are removed, and only values at least as large as are retained.
Example 5.
Let be an integer value, and . Their binary representations are The two’s complement of is computed as Applying the bitwise AND operation yields The result retains only values that are at least , ensuring that all smaller values are removed.
Lemma 6.
Given an integer , the smallest remaining nonzero bit is selected using the operation This operation isolates the least significant set bit of in constant time.
Proof.
The expression represents the two’s complement of , which is given by The two’s complement negation flips all bits of up to the least significant set bit, which is then incremented by . This ensures that has exactly one bit set at the position of the least significant in and all lower bits reset to .
Applying the bitwise AND operation, retains only the least significant set bit in , as all higher bits are set to .
Example 7.
Let , whose binary representation is Computing the two’s complement: Applying the bitwise AND operation: Thus, isolates the least significant set bit of , ensuring that the smallest valid value possible is selected.
Due to Lemma 6 the smallest valid match can be found in constant time.
Given a determinate pattern and an indeterminate text , both of length , we first compute . This vector captures the relative ordering of characters in .
When analyzing after , we define , and let denote the value previously selected (with ). The selected value from must be strictly greater than .
-
If is determinate, we verify that is a power of two (as stated in Lemma 2) and that it preserves the increasing order with respect to the previously selected value, namely . If either condition fails, the match is rejected; otherwise, we set and proceed with the comparison.
If all positions satisfy the above conditions without failure, then order-preserving matches in the bitwise-compatible encoding model.
Example 8.
Let and be two strings such that and . Computing the rank function for , we find that has rank 3, has rank 2, has rank 1, and has rank 4, yielding . Processing in order of increasing rank , the first value examined is , which is indeterminate. Since it is the first selection, we take the smallest power of two in , which is Thus, we select 1. The next value, , is also indeterminate. Since the previous selection was 1, we remove values smaller than 1 using The smallest remaining power of two is Thus, we select 4. The third value, , is indeterminate. Since the previous selection was 4, we remove values smaller than 4 using The smallest remaining power of two is Thus, we select 16. Finally, is determinate and greater than , so we select 64. The final sequence selected is therefore , which correctly satisfies , confirming an order-preserving match.
Algorithm 1 checks whether an indeterminate string can be matched to a pattern while preserving order. The algorithm first sorts the positions of by rank (line 2), then iterates through them in that order. At each step, it checks whether the corresponding entry in is a determinate or indeterminate character (line 8). If it is indeterminate, the algorithm selects the smallest valid candidate that preserves the ordering (line 14). Lines 9 and 15 verify whether the ordering constraints are violated; if so, the algorithm terminates early. The helper functions isPowerOfTwo and findSmallestValid ensure that only valid candidates are considered.
The correctness of this method follows from the properties of rank transformation and greedy selection strategy. Since the selection process respects the ordering constraints at each step, any alternative valid sequence must be lexicographically dominated by the computed selection. If no valid selection exists at any step, then no order-preserving match can exist. The efficiency of the approach is ensured by the constant-time operations used to determine, filter, and select the smallest remaining bit. The general complexity consists of computing the rank transformation in time and processing each position of in constant time, leading to an optimal time complexity of . The pseudo code of this method is shown in Algo. 1.
It is worth noticing that the structure of the proposed OPPM algorithm lends itself to parallelization in a straightforward way. Each determinate character imposes a strict ordering constraint, which partitions the rank vector into independent segments. Each thread starts using the determinate value as lower bound and selects the smallest valid values greedily. This yields fine-grained, scalable parallelism with very limited synchronization overhead. We formalize this in Theorem 9, which establishes the parallel work and time bounds.
Theorem 9.
Let be a determinate pattern and an indeterminate text of length . Let be the number of determinate positions in , and let . For any number of processors , the OPPM on can be solved with total work and parallel time, where is the length of the longest segment. If the segments are balanced so that , the running time improves to . Synchronization consists of a constant-time hand-off of one boundary value per segment and the final combination of Boolean flags, which incurs work.
Proof.
Let be the set of determinate positions of , and let these positions induce contiguous segments on the rank order of , denoted . Segment contains all positions up to in the rank order; for , contains the positions strictly between and ; and contains the positions after . Let be the number of processors. We assign each to one distinct processor (if , we assign multiple segments to some processors by any balanced partition of ).
Independence.
By the definition of the OPPM procedure, the selected value at the last position of provides a single lower bound for all choices within , while choices internal to do not affect with except through the final selected value of . Hence, conditioned on the single boundary value passed from , all operations within are independent of other segments. The first segment has no such lower bound.
Work.
Each position of is processed a constant number of times (consistent with the word-RAM assumption where bitwise operations and tests such as power-of-two, masking, and least-significant-bit selection are unit cost). The synchronization adds at most additional operations: a single-word hand-off per segment boundary and the Boolean flags for the final reduction. Therefore, the total work of the parallel algorithm is .
Span / parallel time.
Let denote the number of positions of handled in , with . With a balanced assignment over processors, the maximum load per processor is , so the parallel time due to local computations is . The only inter-segment dependency is the hand-off of the single boundary value from to for each , which are constant-time in the word-RAM model, and the final Boolean reduction, which has span . Thus the total parallel time is .
Putting everything together, the parallel running time is with total work . Since , the attainable speedup is upper-bounded by , as at most one processor can be assigned per segment.
Remark 10.
On a CRCW PRAM the Boolean flags can be combined by a single concurrent AND in time. On the more natural CREW PRAM, each processor writes its Boolean value into an array and the flags are combined using a tournament tree, which takes time and work.
Example 11.
Consider the indeterminate text with binary decompositions . The determinate entries (powers of two) are at positions and . Assume the pattern induces the rank order . With , this yields three segments: , , .
In (no lower bound) we pick from , then from , then the determinate . In (lower bound ) we pick from , then . In (lower bound ) we pick from , then from . Thus the selected assignment is , with , so order-preserving matches . The segments are independent once boundaries (determinate characters) are fixed, and can thus be verified in parallel.
Remark 12.
An equivalent way to express the OPPM problem is through permutations. Let be the rank permutation induced by the determinate pattern and define for each Then checking whether order-preserving matches amounts to verifying that itself forms a non-decreasing sequence (depending on whether ties are allowed). The parallel algorithm can be viewed as partitioning into independent segments at the determinate positions.
3.1 Space Complexity
Previous approaches to order-preserving matching on indeterminate strings, such as the one presented in [13], require space, where is the length of the pattern and is the maximum number of symbols per indeterminate position.
In contrast, our method does not require any additional space to store the bitwise representation, as all encoding and comparisons can be performed online. Furthermore, assuming that the pattern and the text have the same length, the result of the matching process can be stored in-place, that is, directly within the memory allocated for the text itself. However, to extend the method to handle patterns and texts of different lengths, an additional linear size buffer in the length of the pattern may be required to store the final solution.
4 Parameterized Matching in Indeterminate Strings
Let be a determinate string drawn from an alphabet of size , partitioned into two disjoint subsets: a fixed alphabet and a parameterized alphabet , such that , with and .
Let be an indeterminate string of the same length as , drawn from an alphabet of size , also partitioned into the same fixed alphabet and a parameterized alphabet , such that , with .
Parameterized matching allows dynamic mappings from characters in that belong to to characters in that belong to , provided the structural consistency of is preserved. Thus, to define an injective function from to , it is necessary that .
Additionally, we consider that may include indeterminate positions, where each represents a subset of . To support efficient matching under these conditions, we use a bitwise encoding scheme in which each character is represented by a bitmask. This allows filtering via bitwise operations.
Indeterminate Parameterized Matching
Input: A determinate pattern and an indeterminate text of length , where each .
Output: true if there exist an assignment of and an injective mapping such that, for every position , fixed symbols match exactly and parameterized symbols are matched through ; false otherwise.
Initially, each parameterized character is assigned a bitmask value: which permits it to map to any symbol in . The algorithm proceeds by scanning the string and refining these bitmasks using the corresponding entries in . When is a fixed character, it must match exactly ; if not, the match fails immediately. If is parameterized, the characters in are encoded as a bitmask, and this is intersected with the current via: removing any characters from the mapping that do not appear in .
A parameterized match is only possible if every character in retains at least one valid mapping after filtering, i.e., for all . However, this condition does not guarantee that a valid one-to-one mapping exists.
Example 13.
Let and and , with and . Initially, all parameterized characters are assigned the bitmask . The fixed characters a and b match exactly at their positions. For E, the corresponding is encoded as , and the mask is updated via . Similarly, for F, with encoded as , the update is . After this step, both and remain non-zero. Still, since they share a common mapping candidate belonging to the parameterized-alphabet (e.g., Z), uniqueness must be verified.
To enforce uniqueness, we reduce the problem to a bipartite graph matching instance. We construct a bipartite graph , where is the set of parameterized characters in the pattern , and is the set of parameterized characters in the text . We assume . An edge exists between and if the bitmask associated with contains a at the position corresponding to , indicating compatibility.
A valid match exists if and only if there is a maximum matching in that covers all nodes in , ensuring a unique assignment for each parameterized symbol in the pattern. This can be efficiently computed using the Hopcroft-Karp algorithm, which runs in time in the general case [14].
In our setting, we have and , so the total number of vertices is . The number of edges is determined by the bitmask encoding and is upper-bounded by in the case of full compatibility.
Therefore, the Hopcroft-Karp algorithm runs in time in the general case, and up to in the worst case. Notably, in the fully dense case where is a complete bipartite graph, the classical bound from Hopcroft and Karp applies, yielding a worst-case complexity of [14].
In practice, however, this step is often significantly faster due to the sparsity of the compatibility graph and the typically low degree of ambiguity. The pseudo-code for this procedure is provided in Algo. 2, which we call the Parameterized Indeterminate String Matching (PISM).
We now analyze the computational complexity of the proposed parameterized matching algorithm. The procedure consists of three main steps: filtering the parameterized symbols using bitwise operations, constructing a bipartite graph based on the remaining valid mappings, and computing a maximum matching to enforce one-to-one assignments.
The filtering phase takes time due to constant-time bitwise operations per position. Constructing the bipartite graph from the bitmask representations requires time in the worst case. The final matching step, performed via the Hopcroft–Karp algorithm, runs in time.
Consequently, the overall time complexity of the algorithm is: . The space complexity depends primarily on the representation of the bipartite graph. Using an adjacency matrix yields a worst-case space usage of . Alternatively, an adjacency list may be employed to reduce space consumption in sparse instances, although the asymptotic bound remains the same.
Algorithm 2 implements parameterized matching between a determinate pattern and an indeterminate text under the alphabets and . It first initializes masks for all parameterized symbols (lines 2–3). Then, in the presence of indeterminate characters, it updates these masks based on the observed matches between and (line 9). Finally, a bipartite graph is constructed from the masks (line 10), and the existence of a full matching (line 11) determines whether matches under the parameterized model.
5 Allowing Mismatches in the Parameterized Matching
The problem of parameterized matching with mismatches [1] has been recently revisited by Saha et al. [20]. In their formulation, given two deterministic strings and of equal length , a weighted bipartite graph is constructed, where . Each edge is weighted by the number of positions such that and . The minimum number of mismatches is then where denotes the maximum weighted matching of and . This reduction enables efficient algorithms for approximate parameterized matching, including cases with a bounded number of mismatches. We now extend this framework to the case of a determinate string and an indeterminate string , formally defined as follows:
Indeterminate Parameterized Matching with Mismatches
Input: A determinate pattern and an indeterminate text of length , where each .
Output: The minimum number of mismatches over all assignments of and injective mappings .
Definition 14 (Parameterized Matching with Mismatches on Indeterminate Texts).
Given a determinate pattern of length and an indeterminate text , where each , the parameterized matching with mismatches problem consists in finding a bijective mapping and a determinate assignment of minimizing the number of positions such that Equivalently, the minimum number of mismatches is given by The pair achieving this minimum defines an optimal parameterized alignment between and .
In the exact setting, we initialized each mask with all ones and progressively refined it via bitwise AND operations, thereby filtering out incompatible candidates until only consistent bijections remained. To allow mismatches, this logic is inverted: since each is a set of possible symbols, the goal is to accumulate all compatibilities rather than restrict them. We therefore initialize every parameterized symbol with an all-zeros mask and update it by bitwise OR: so that all candidates compatible with are preserved. The OR-masks specify adjacency in the bipartite graph but not edge multiplicities. To capture frequencies, we introduce an auxiliary array of size such that counting how many times appears in the subsets of . Consequently, for each pair , the weight of edge equals the number of positions with and . This generalizes the deterministic case, where all edges had unit weight. The resulting bipartite graph is thus defined by OR-masks (adjacency) and the array (weights). The maximum weighted matching of this graph again determines the optimal alignment, and the minimum number of mismatches is
Example 15.
Let and , and let . Consider the determinate pattern and the indeterminate text In this example, the number of parameterized positions is corresponding to positions , , and of both strings.
In contrast to the exact setting, we initialize all masks to and update them using bitwise OR. Encoding as , , and , respectively, the sets , , and are encoded as , , and . Thus, we obtain
Hence, both E and F are compatible with .
Next, we compute the edge weights of the bipartite graph. Each edge is weighted by the number of positions such that and . Therefore, we obtain the bipartite graph shown below, where the left side corresponds to and the right side to . All edges have unit weight.
The thick edges indicate one possible maximum weighted matching, while dashed edges represent alternative compatible assignments.
A maximum weighted matching selects two disjoint edges, for instance and with total weight . Since , the minimum number of mismatches is We now verify this bound explicitly.
The pattern contains three non-static positions, namely E at positions and , and F at position . Under the bijection position matches, position matches, but position does not, since does not contain Y. Similarly, under the bijection position matches, position matches, but position does not, since does not contain Z. Therefore, exactly one mismatch is unavoidable, and
This example shows how OR-masks encode local compatibility, while the weighted matching enforces global consistency through a bijection, leading to an optimal alignment.
Lemma 16.
The OR-mask and frequency array for an indeterminate text of length can be constructed in time.
Since only the edge weights differ while the graph structure is preserved, the algorithm of Saha et al. [20] remains directly applicable, with time complexity . Constructing the OR-masks and requires only preprocessing, so the dominant cost remains the FFT-based polynomial multiplication [4] and the maximum weighted bipartite matching, yielding the same asymptotic complexity as in the deterministic case.
6 Experimental Results
The proposed algorithms were implemented in C.111Source code available at https://github.com/marfra99x/SCER-ISM. Experiments were conducted on a MacBook Pro equipped with a 2.7 GHz Intel Core i7-8559U (4 cores), with 16 GB RAM. All algorithms were compiled using the -O3 optimization flag.
Performance was measured in terms of search execution time (milliseconds) on randomly generated texts. We report two complementary experiments, shown as the two plots of Fig. 1.
Within the context of order-preserving pattern matching (OPPM), we compare two approaches: OLD, referring to the algorithm proposed by Henriques et al. [13]; and NEW, representing the bitwise-compatible method introduced in this work. For the parameterized string matching setting, we evaluate the PISM algorithm, designed to support efficient bit-parallelism in handling variable symbol classes and the Mismatches Parameterized Indeterminate String Matching (MPISM)222Although MPISM is described in the paper using a fast FFT-based procedure, in our experiments we employ the Hungarian algorithm [16] for maximum weighted bipartite matching, as it offers a simpler and more straightforward implementation. Nonetheless, the FFT-based approach outlined in the paper could yield faster results.. In the left plot, the x–axis varies according to the specific setting. For OPPM, it represents the number of uncertain characters per position, denoted by . For PISM, it corresponds to the size of the parameterized alphabet of the text, , which captures the diversity of symbol classes. For MPISM, we fix three different sizes of the parameterized alphabet (small, medium and large) and instead vary the number of allowed mismatches in the input to assess performance. Additionally, in the right plot, all parameters are fixed and only the text length varies, taking values between and . The results in Fig. 1 show a substantial and consistent speedup of NEW over OLD across all tested regimes. On average, our method outperforms the prior state-of-the-art by over , confirming the benefits of the bit-parallel encoding. PISM maintains competitive performance while MPISM displays the expected growth as and increase, reflecting the underlying matching complexities.
These results confirm the effectiveness of our algorithms not only in theoretical terms but also in practice, particularly for large-scale texts where traditional set-based comparisons become a performance bottleneck. The combination of sum-free sequence encoding and greedy selection strategies leads to measurable improvements in runtime performance.
7 Conclusions and Future Work
In this work, we introduced efficient algorithms for matching a determinate pattern against an indeterminate text under two notable substring consistent equivalence relations (SCERs): order-preserving and parameterized matching. By leveraging a bitwise-compatible encoding based on sum-free sequences, our approach enables constant-time character comparisons and compact set representations. The resulting techniques achieve an optimal time complexity of for order-preserving matching and for parameterized matching, where and denote the number of distinct parameterized symbols, in the pattern and text, respectively.
The efficiency of our approach can be further enhanced through pre-sampling strategies. Sampling techniques have proven effective in reducing redundant search spaces and filtering unpromising regions in various exact and approximate matching tasks [8]. Applying such techniques in the context of indeterminate matching may enable early pruning and tighter complexity bounds, especially in large-scale or high-ambiguity datasets.
In addition, we extended the parameterized framework to handle mismatches in the presence of indeterminate positions, we showed that the construction naturally reduces to the same weighted bipartite graph formulation of Saha et al. [20]. As a result, their FFT-based computation and matching algorithm carry over unchanged, with only a linear preprocessing overhead. This demonstrates that approximate parameterized matching can also be tackled efficiently in the indeterminate setting, further broadening the scope of tractable problems under SCERs. Future directions include extending this asymmetric framework to other SCER models, integrating adaptive sampling mechanisms, and optimizing for real-time or streaming contexts where input uncertainty dynamically evolves.
References
- [1] Alberto Apostolico, Peter Erdős, and Moshe Lewenstein. Parameterized matching with mismatches. J. Discrete Algorithms, 5:135–140, 2007. doi:10.1016/j.jda.2006.03.014.
- [2] Brenda S. Baker. A theory of parameterized pattern matching: algorithms and applications. In S. Rao Kosaraju, David S. Johnson, and Alok Aggarwal, editors, Proceedings of the Twenty-Fifth Annual ACM Symposium on Theory of Computing, May 16-18, 1993, San Diego, CA, USA, pages 71–80. ACM, 1993. doi:10.1145/167088.167115.
- [3] R.S. Bird. Two dimensional pattern matching. Information Processing Letters, 6(5):168–170, 1977. doi:10.1016/0020-0190(77)90017-5.
- [4] Elbert Oran Brigham. The Fast Fourier Transform. Prentice-Hall, Englewood Cliffs, N.J., 1974.
- [5] Maxime Crochemore, Christophe Hancart, and Thierry Lecroq. Algorithms on Strings. Cambridge University Press, 2007.
- [6] Hossein Dehghani, Thierry Lecroq, Neerja Mhaskar, and William F. Smyth. Practical KMP/BM style pattern-matching on indeterminate strings. Discrete Applied Mathematics, 370:22–33, 2025. doi:10.1016/J.DAM.2025.02.032.
- [7] Simone Faro, Dominik Köppl, Thierry Lecroq, and Francesco Pio Marino. marfra99x/SCER-ISM. Software, swhId: swh:1:dir:c33fa1f2fdf35f4030601b03c54ad27d5931dfd0 (visited on 2026-05-27). URL: https://github.com/marfra99x/SCER-ISM, doi:10.4230/artifacts.26165.
- [8] Simone Faro, Francesco Pio Marino, and Arianna Pavone. Efficient online string matching based on characters distance text sampling. Algorithmica, 82(11):3390–3412, 2020. doi:10.1007/S00453-020-00732-4.
- [9] Simone Faro, Francesco Pio Marino, and Arianna Pavone. Improved characters distance sampling for online and offline text searching. Theoretical Computer Science, 946:113684, 2023. doi:10.1016/J.TCS.2022.12.034.
- [10] Simone Faro, Francesco Pio Marino, Arianna Pavone, and Antonio Scardace. Towards an efficient text sampling approach for exact and approximate matching. In Jan Holub and Jan Zdárek, editors, Prague Stringology Conference 2021, Prague, Czech Republic, August 30-31, 2021, pages 75–89. Czech Technical University in Prague, Faculty of Information Technology, Department of Theoretical Computer Science, 2021. URL: http://www.stringology.org/event/2021/p07.html.
- [11] Paweł Gawrychowski, Samah Ghazawi, and Gad M. Landau. On indeterminate strings matching. In 31st Annual Symposium on Combinatorial Pattern Matching (CPM 2020), volume 161 of Leibniz International Proceedings in Informatics (LIPIcs), pages 14:1–14:14. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2020. doi:10.4230/LIPIcs.CPM.2020.14.
- [12] Dan Gusfield. Algorithms on Strings, Trees and Sequences: Computer Science and Computational Biology. Cambridge University Press, 1997.
- [13] Rui Henriques, Alexandre P. Francisco, Luís M. S. Russo, and Hideo Bannai. Order-preserving pattern matching indeterminate strings. In Gonzalo Navarro, David Sankoff, and Binhai Zhu, editors, Annual Symposium on Combinatorial Pattern Matching, CPM 2018, July 2-4, 2018 - Qingdao, China, volume 105 of LIPIcs, pages 2:1–2:15. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2018. doi:10.4230/LIPIcs.CPM.2018.2.
- [14] John E. Hopcroft and Richard M. Karp. An algorithm for maximum matchings in bipartite graphs. SIAM Journal on Computing, 2(4):225–231, 1973. doi:10.1137/0202019.
- [15] Tomohiro I, Shunsuke Inenaga, and Masayuki Takeda. Palindrome pattern matching. Theoretical Computer Science, 483:162–170, 2013. doi:10.1016/J.TCS.2012.01.047.
- [16] Harold W. Kuhn. The Hungarian method for the assignment problem. Naval Research Logistics Quarterly, 2(1-2):83–97, 1955. doi:10.1002/nav.3800020109.
- [17] Gonzalo Navarro and Mathieu Raffinot. Flexible Pattern Matching in Strings: Practical On-Line Search Algorithms for Texts and Biological Sequences. Cambridge University Press, 2002. doi:10.1017/CBO9781316135228.
- [18] Petr Procházka and Jan Holub. On-line searching in IUPAC nucleotide sequences. In Elisabetta De Maria, Ana L. N. Fred, and Hugo Gamboa, editors, Proceedings of the 12th International Joint Conference on Biomedical Engineering Systems and Technologies (BIOSTEC 2019) - Volume 3: BIOINFORMATICS, Prague, Czech Republic, February 22-24, 2019, pages 66–77. SciTePress, 2019. doi:10.5220/0007382900660077.
- [19] M. Sohel Rahman, Costas S. Iliopoulos, and Laurent Mouchard. Pattern matching in degenerate DNA/RNA sequences. In M. Kaykobad and Md. Saidur Rahman, editors, Workshop on Algorithms and Computation 2007 - Proceedings of First WALCOM, 12 February 2007, Dhaka, Bangladesh, pages 109–120. Bangladesh Academy of Sciences (BAS), 2007.
- [20] Apurba Saha, Iftekhar Hakim Kaowsar, Mahdi Hasnat Siyam, and M. Sohel Rahman. Algorithms for parameterized string matching with mismatches. arXiv, 2024. doi:10.48550/arXiv.2412.00222.
