Set Parameterized Matching via Multi-Layer Hashing
Abstract
We study the set parameterized matching problem, a generalization of the classical parameterized matching problem introduced by Baker [7, 8]. In set parameterized matching, both the pattern and text are sequences where each position contains a set of characters rather than a single character. Two set-strings parameterized match if there exists a bijection between their alphabets that maps one to the other set-wise. Boussidan [12] introduced this problem for the case of equal-length set-strings. We present a randomized algorithm running in time with high probability, where is the text size and is the pattern size. Our approach employs a novel three-layer hashing scheme based on Karp-Rabin fingerprinting that addresses the challenges of (1) the size blowup in representations of the problem, (2) set-to-set matching, and (3) the dynamic nature of encodings of text substrings during pattern scanning.
Keywords and phrases:
Set Parameterized Matching, Pattern Matching, Randomized Algorithms, Hashing, Parameterized MatchingFunding:
Moshe Lewenstein: Work on this paper was supported by ISF grant # 2760/25 awarded by the Israel Science Foundation.Copyright and License:
2012 ACM Subject Classification:
Theory of computation Pattern matching ; Mathematics of computing Probabilistic algorithmsEditors:
Philip Bille and Nicola PrezzaSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
The parameterized pattern matching problem, introduced by Baker [6, 7, 8], seeks all occurrences of a pattern in a text where an occurrence is defined not by exact character matches but by consistent character renaming. Formally, the pattern occurs at position if there exists a bijection from the pattern alphabet to the text alphabet such that for all . This problem has found numerous applications in software maintenance [6], plagiarism detection, computational biology [25], and beyond [24].
1.1 Prior Work
The study of parameterized matching was pioneered by Baker [6, 7], who introduced the concept to identify duplicated code in large software systems. The core innovation was the “predecessor string” (or prev) representation, which converts a string into an integer sequence where each character is replaced by the offset to its previous occurrence. A key observation is that two strings parameterized match if and only if their prev transformations are identical. This insight allowed for efficient matching regardless of specific variable names, provided the usage patterns were consistent. This discovery enabled -time algorithms [1] and led to the development of parameterized suffix trees [8] and suffix arrays [14]. Subsequent research has explored the theoretical boundaries and practical variations of the problem:
1.2 Set Parameterized Matching
While classical parameterized matching handles sequences of single characters, many real-world scenarios involve ambiguity or multiple valid interpretations at a single position. Boussidan [12] in his PhD thesis (see also [11]) was concerned about comparing 18th century French plays, where the characters of the play are important, but each scene has multiple characters within. To address this, Boussidan extended the model of parameterized matching to set parameterized comparison, where for two equal-length strings, each position in both contains a set of characters, and the question is whether they parameterize match. We call these strings containing sets, set-strings. Boussidan’s original algorithm relied on bipartite matching. This approach is computationally expensive, requiring time for comparison alone. In this paper, we consider the full pattern matching version of the problem:
Problem 1 (Set Parameterized Matching).
Given a text and a pattern where each , report all positions such that set-parameterized matches .
1.3 Our Contributions
We present a linear time randomized algorithm for set parameterized matching which is novel in its solution approach. This even dramatically improves the previous bipartite matching approaches for the special case of set parameterized comparison.
Theorem 1 (Main Result).
Given a set-string text and set-string pattern over alphabet , where and , we can report all set-parameterized matches in time with high probability using a Monte Carlo randomized algorithm with error probability at most .
Key to our result is the introduction of a new structural definition we term the multiset offset representation. Unlike classical predecessor pointers which capture only local history, this representation preserves the global distribution of every character, ensuring that the necessary bijection properties hold even when multiple characters share identical positions. To process this representation, which can be quadratically large in the worst case, we employ a novel three-layer hashing scheme:
-
1.
Layer 1: Hash the offset set of each character to a single integer using Karp-Rabin fingerprinting, compressing the interaction history.
-
2.
Layer 2: Hash the multiset of these values at each position to a single integer (“mashing”), enabling efficient set-to-set comparisons that respect multiplicities.
-
3.
Layer 3: Apply a rolling Karp-Rabin hash to the sequence of mashed values to enable linear time processing of sliding windows.
As a warmup to the main result, we also demonstrate an efficient solution for the comparison problem:
Theorem 2 (Set-String Comparison).
Given two set-strings and over alphabet , where and , we can determine whether they set-parameterized match in time with error probability at most .
1.4 Organization
The remainder of the paper is organized as follows. Section 2 defines our model and the necessary notation. Section 3 serves as a warmup, proving Theorem 2 for comparing two set-strings. Section 4 details our main pattern matching algorithm, proving Theorem 1. Finally, we analyze the correctness and complexity in Section 5.
2 Model and Definitions
2.1 Notation and Basic Definitions
Throughout this paper, we denote by a finite alphabet and by the set of all finite strings over . We assume that . If not, we sort and rename the alphabet characters. For a string , we write for its size (length) and for its -th character, where . We use the notation for positive integers . For a prime , we denote the field , the integers modulo .
2.2 Classical Parameterized Matching
We begin by recalling the classical parameterized matching framework of Baker [7, 8], which forms the foundation of our work.
Definition 3 (Parameterized Match [7]).
Let be two strings of equal length over alphabet . We say that and parameterized match, denoted , if there exists a bijection such that for all .
Remark 4.
The bijection in Definition 3 must be defined on the entire alphabet , though it need only be consistent on the characters actually appearing in and . Some works distinguish between “constant” and “parameter” alphabets where acts as the identity on ; for simplicity, we consider the case where all characters are parameters (equivalently, ).
Problem 2 (Parameterized Pattern Matching).
- Input:
-
A text and a pattern over alphabet .
- Output:
-
All positions such that .
Baker’s key insight was to transform the string into a structural representation invariant under permutation. This is the prev transformation (or predecessor encoding):
Definition 5 (Prev Transformation [7]).
For a string over alphabet , the prev transformation is the integer sequence where
Lemma 6 (Correctness of Prev [7]).
For strings over , we have if and only if (equality of integer sequences).
2.3 Set-Strings and Set Parameterized Matching
We now formalize the set parameterized matching model, which generalizes the concepts above to sequences of sets.
Definition 7 (Set-String).
A set-string of length over alphabet is a sequence where each is a finite set of characters. The length of is and its size is . We write for the subsequence .
Definition 8 (Set Parameterized Match).
Let and be two set-strings of equal length over alphabet . We say that and set-parameterized match, denoted , if there exists a bijection such that for all : where for any set .
Remark 9.
Problem 3 (Reformulation of Set Parameterized Matching).
- Input:
-
A text and a pattern , both set-strings over alphabet .
- Output:
-
All positions such that .
For the special case where we call the problem the Set Parameterized Comparison as all that is required is to verify if the strings parameterize match each other.
2.4 Offset Representation
A naive extension of the prev transformation to set-strings – where one replaces every character in every set with its predecessor offset – fails because it destroys the continuity of character chains. Consider the following counter-example: Let set-string and If we simply replace each character with its prev value, the resulting sets of prevs match perfectly at every position:
The sets of prevs are identical, yet there is no valid parameterization. In , the character appearing at 13 (“a”) is the one that started at 5. In , the character at 13 (“c”) is the one that started at 2. The simple set of prevs at position 8 obscures which prev belongs to which character chain. To overcome this, we represent all appearances of a specific character “together” as a structural unit. While a “prev set” (listing all predecessor offsets for a character) might capture this structure, it is not convenient for the rolling hash updates required by our algorithm. Instead, we chose to represent this “togetherness” using offset sets. Since a character may appear in multiple sets, and a set contains multiple characters, a single “previous occurrence” is ill-defined. We must instead track the set of previous offsets. This motivates the following definition.
Definition 10 (Offset Set).
Let be a set-string over , and let . Suppose appears in at positions (i.e., for all ). The offset set of in is
If does not appear in , we define .
Note that multisets are necessary as we may have two characters in one set with the same offset set. We need to keep both of them as the multiplicity of characters in the compared set-strings must be equal. With the offset set defined for each individual character, we now aggregate this information to represent the structure of the entire set-string. At any given position in the string, multiple characters may be present. To fully capture the parameterization constraints at this position, we must collect the offset sets of all characters appearing there, forming the signature of that position, allowing us to compare the structural roles of characters across two different strings.
Definition 11 (Multiset Offset Representation).
For a set-string of length , the offset representation at position , denoted , is the multiset of offset sets for all characters appearing at .
and
In continuation with the former example:
Observation 12.
For a set-string over alphabet , each offset set has size at most . Therefore, contains exactly offset sets, each of size at most . Letting denote the total number of character occurrences, in the worst case, (the total number of integers in the offset representation) is .
The following lemma, proof in appendix, shows that the Multiset Offset Representation provides a necessary and sufficient condition for set parameterized matching.
Lemma 13.
Let and be set-strings of length . Then if and only if (where equality implies equality of the sequence of multisets).
2.5 Challenges for Set Parameterized Comparison and Matching
While Lemma 13 successfully reduces set-parameterized comparison to checking equality of offset representations, it does not immediately yield an efficient algorithm for set parameterized comparison and, definitely, not for set parameterized matching, due to two distinct hurdles:
-
1.
Size blowup: By Observation 12, the offset representation can be quadratically larger than the input. Comparing these representations directly is prohibitively expensive.
-
2.
Dynamic offset sets: For set parameterized matching, we compare against sliding windows . The offset sets depend on the start index and must be recomputed for each position. This contrasts with classical pattern matching, where the text “characters” remain static throughout the algorithm.
2.6 Karp-Rabin Fingerprinting
Our algorithms employ the Karp-Rabin fingerprinting technique [19]. We distinguish between two variants of the hash function, depending on whether the input is treated as a sequence (order matters) or a multiset (order irrelevant).
Definition 14 (Sequence Hash).
Let be a prime and . For a sequence of integers , the sequence hash treats the elements as coefficients of a polynomial:
Definition 15 (Set/Multiset Hash).
Let be a multiset of integers drawn from a universe . Let denote the multiplicity of value in . The set/multiset hash treats the values as exponents:
Lemma 16 (Collision Probability [19]).
Let be a prime and be chosen uniformly at random.
-
1.
Sequence Collision: Let and be two distinct sequences of length at most . Then:
-
2.
Multiset Collision: Let and be two distinct multisets containing values from the universe . Then:
Proof.
In both cases, the collision condition is equivalent to being a root of the non-zero difference polynomial over the field . By the fundamental theorem of algebra, the number of roots is bounded by the degree of .
-
1.
For sequences, . The degree is bounded by the maximum index, which is .
-
2.
For multisets, . The degree is bounded by the maximum value such that counts differ, which is at most .
Dividing the degree by the field size yields the probability bound.
2.7 Rolling Hashes
In the classical Rabin-Karp pattern matching algorithm [19], the rolling hash essentially computes a fingerprint for every window of length in the text, and compares it to the fingerprint of the pattern.
Definition 17 (Rolling Hash).
For a sequence where each , and a window size , define
for . This is the rolling hash of the window .
A key property of this scheme is the ability to efficiently update the hash value as the window slides from one position to the next.
Observation 18 (Efficient Rolling Hash Update).
Given , we can compute in time via
Our algorithm, to appear later, builds upon this rolling concept. However, adapting it to parameterized matching, and specifically set parameterized matching, introduces significant complexity: the effective value of a “character” (its offset) is relative to the window’s start position and thus changes dynamically as the window rolls.
3 Set Parameterized Comparison
In this section, we prove Theorem 2 by presenting an efficient algorithm for set parameterized comparison, i.e., determining whether two set-strings of equal length set-parameterized match. This algorithm serves as a conceptual warmup for our main pattern matching algorithm and introduces the first two layers of our hashing scheme.
3.1 Algorithm Overview
The algorithm proceeds in three logical steps to progressively compress the set-string structure:
-
1.
First, we compute the explicit offset sets for all characters in both set-strings.
-
2.
Next, we hash each offset set to a single integer fingerprint using Karp-Rabin hashing (Layer 1).
-
3.
Finally, we hash the set of fingerprints at each position to obtain a single value, allowing for linear comparisons (Layer 2).
3.2 Layer 1: Hashing Offset Sets
We first address the computational cost of generating the offset sets. Recall that .
Lemma 19 (Offset Set Computation).
Given a set-string over alphabet of size , we can compute for all in time and space .
Proof.
We perform a single pass over the set-string. We maintain a hash table to track the first occurrence of each character, and for each , a list initially empty.
The initialization loop takes time, which is . The outer loop runs times, and the inner loop processes each character in each set. In total, we process exactly character-position pairs. Each operation takes expected time with hashing, giving a total time complexity of .
Once the offset sets are computed, we compress them using the set hash function from Def. 15.
Definition 20 (Layer 1 Hash).
Let be a prime and let be chosen uniformly at random. For an offset set , the Layer 1 hash function is:
Collision Analysis.
By the definition, the Layer 1 hash is exactly the multiset hash . The elements of the offset sets are integers drawn from the universe . We apply Lemma 16 (Multiset Collision case) with universe bound , yielding for :
3.3 Layer 2: Hashing Sets of Fingerprints
After applying Layer 1, each position in set-string is represented by a multiset of fingerprints:
To compare positions efficiently, we must compare these multisets. We therefore apply a second layer of hashing to “mash” these multisets into single values. Specifically, we use the multiset hash function from Definition 15.
Definition 21 (Layer 2 Hash).
Let be a prime and let be chosen uniformly at random. For a multiset of fingerprints from , the Layer 2 hash function is:
We call the resulting hash value the mashed value of the position and the mashed representation of a set-string is the sequence where
Collision Analysis.
By the definition, Layer 2 is also the multiset hash . The elements of the multisets are Layer 1 fingerprints, which are integers drawn from the universe . Therefore, we can apply Lemma 16 (Multiset Collision case) with universe bound , yielding:
3.4 Set Parameterized Comparison Algorithm
The full procedure for set parameterized comparison, comparing two set-strings, consisting of applying the 2-level hash to each, is formalized in Algorithm 1 and appears in the appendix.
Theorem 22 (Correctness of Comparison Algorithm).
Algorithm 1 correctly determines whether with probability at least .
Proof.
Completeness.
Assume . By Lemma 13, we know . This implies that for every position and every , there exists a corresponding such that , and vice versa. It follows deterministically that:
-
for all (as sets), and consequently,
-
for all .
Thus, the algorithm correctly returns true.
Soundness.
Assume . By Lemma 13, . Thus, there must exist some position where the sets of offset sets differ: . Let be the event that “there exist distinct offset sets with .” By choosing and taking the union bound over all pairs of distinct characters, we bound the probability of this collision:
Conditioned on , the hash function is injective on the offset sets appearing in and . Since , it must be that as sets of fingerprints. Next, let be the event that “there exist distinct sets with .” Choose . We are comparing multisets (one for each position ). For any specific position, the collision probability is bounded by (by Lemma 16 with universe ). Applying the union bound over all positions:
Conditioned on , we are guaranteed that , and so the algorithm returns false. The overall error probability is bounded by the sum of probabilities of these collision events:
This concludes the proof of Theorem 2, with a summary appearing in the index.
4 Set Parameterized Matching Algorithm
We now present our main algorithm for Problem 3, the problem of Set Parameterized Matching, proving Theorem 1.
4.1 The Rolling Hash Challenge
Recall from Section 2 (Definition 17) that the Rabin-Karp rolling hash allows for efficient updates when sliding a window over a fixed sequence of integers. In our context, the natural candidate for such a sequence is the sequence of Layer 2 mashed values, . A direct application of the standard rolling hash for a window of size starting at text position would be:
where is some prime, , and represents the Layer 2 hash of the offset sets at text position .
The Dynamic Offset Problem
However, this standard approach fails because the values are not static. In set parameterized matching, the offset set is defined relative to the first occurrence of inside the current window. When the window slides from to , if a character is dropped from position , the “first occurrence” of changes to its next appearance in the window (say, at relative distance ). Consequently, the offsets of all remaining occurrences of in the window must be decreased by . This changes the Layer 1 hashes () and, crucially, changes the Layer 2 mashed values () for every position where appears. Updating the rolling hash would thus require recomputing up to terms in the summation, which is prohibitively slow.
4.2 Character-Centric Rolling Hash
To handle these dynamic updates efficiently, we restructure the hashing scheme. Instead of viewing as a sum over window positions (which is sensitive to shifting offsets), we swap the order of summation to view it as a sum over alphabet characters. Recall that for the window starting at location , . Substituting this into the standard rolling hash definition:
By swapping the summation order, we group terms by character rather than by position:
This rearrangement separates the structural shape of the encoding of (encoded by ) from the geometric positions of the encoding of (encoded by the inner sum over ). This separation allows us to update the two components independently.
This motivates our formal definition of the components for the character-centric hash. We first isolate the “geometric” component – the inner sum representing the positions of a character.
Definition 23 (Character Position Fingerprint).
Let be a prime and let be chosen uniformly at random. For a character in the window starting at text position , let its position fingerprint be the sum of the position powers for all its occurrences:
where is the relative index of the occurrence within the window.
With the geometric component isolated, the total window hash can be expressed as a weighted sum of these fingerprints, where the weights are determined by the structural shape (offset sets) of each character.
Definition 24 (Layer 3 Hash).
The character-centric Layer 3 hash for the window at text position is:
where is the Layer 1 hash of the offset set of in window .
4.3 Efficient Transition Logic
To achieve our time complexity goals, we must compute from in time proportional only to the number of characters entering or leaving the window, independent of the alphabet size . When sliding the window from to , two distinct types of updates occur:
-
1.
Geometric Shift: Every character remaining in the window shifts left by one position. This implies that for every , the position fingerprint changes: .
-
2.
Structural Change: For characters in (leaving) and (entering), the offset structure may change to a new value .
A naive update is impossible because we cannot iterate over all to apply the geometric shift , nor can we simply multiply the total hash by (since the structural weights for active characters would be incorrectly shifted). Instead, we decompose the total hash into a Stable Component (characters with unchanged structure) and an Active Component (characters appearing at the window boundaries). We process the transition in three steps: Isolate, Shift, and Reintegrate. Let be the set of characters undergoing structural updates.
Step 1: Isolate (Remove Active Terms)
First, we remove the contributions of all “active” characters from the current hash to isolate the “stable” portion. For any stable character , the structural hash remains invariant ().
This step requires operations.
Step 2: Global Shift (Update Stable Terms)
The remaining hash consists essentially of a sum of terms where is constant. The only required update is the geometric shift of positions (). By the linearity of the sum, we can apply this shift globally:
This single multiplication updates the hash for all non-active characters in time. Lazy Fingerprint Maintenance: To support this global shift without updating individual values in memory, we maintain a global rolling multiplier . The stored value for a fingerprint is related to the actual value by . In this step, we simply update .
Step 3: Reintegrate (Add Updated Active Terms)
Finally, we compute the new states for the active characters and add them back to the shifted stable hash. For each :
-
Update Position: We update to reflect any removals (at relative index 0) or insertions (at relative index ). Note that we must multiply any added terms by to align with the current global frame.
-
Update Offset Structure:
-
–
Leaving (): We must remove the first occurrence. Let be the distance to the next occurrence of in the window. The structure updates by shifting the exponents:
(If does not appear again, resets to 0).
-
–
Entering (): We must add the new occurrence at the end of the window. Let be the index of the first occurrence of in the new window (if is new to the window, ). The new relative offset to add is
-
–
We then add the new contribution to the total hash:
This step also takes time .
Note:
-
(1)
The definition of offset sets comes into its main play here, that is, the update of is computable in time because of the structure of the offset set.
-
(2)
In the computation of the entering characters, we assume knowledge of the first occurrence of . We do this by saving linked lists of the locations of each and traverse them while shifting, changing pointers to current first occurrence in each list when characters leave the window. For the sake of brevity, we keep the details to a minimum.
Theorem 25 (Transition Complexity).
The transition from to can be computed in time .
Proof.
Step 2 takes time. Steps 1 and 3 involve iterating only over the characters present at the leaving position and the entering position . All internal lookups (offset lists, hash maps) take time. Thus, the total time is proportional to the number of character occurrences added or removed.
The full algorithm, depicting the above, is detailed in Algorithm 2 in the appendix.
5 Analysis
5.1 Correctness Analysis
We now prove that the hashing scheme correctly identifies matches with high probability.
Theorem 26 (Correctness).
Algorithm 2 reports all valid set-parameterized matches and reports false positives with probability at most .
Proof.
The matching algorithm effectively performs a set-string comparison at each of the text windows. We analyze the error probability by extending the proof of Theorem 22 by choosing primes: , , and .
-
1.
Layers 1 & 2 (Structural Collision): By the analysis in Theorem 22, the probability of a collision in the structural hashing (Layers 1 and 2) for any single window is bounded by:
-
2.
Layer 3 (Rolling Hash Collision): The rolling hash is a polynomial in of degree at most . For any single window, using Lemma 16, the collision probability is:
Total Error.
Applying the union bound over all sliding windows, the total probability of a false positive is:
5.2 Complexity Analysis
Let and . The following theorem summarizes the result. Details appear in the appendix.
Theorem 27 (Complexity).
Algorithm 2 runs in time and uses space .
References
- [1] Amihood Amir, Martin Farach, and S. Muthukrishnan. Alphabet dependence in parameterized matching. Information Processing Letters, 49(3):111–115, 1994. doi:10.1016/0020-0190(94)90086-8.
- [2] Amihood Amir and Gonzalo Navarro. Parameterized matching on non-linear structures. Information Processing Letters, 109(15):864–867, 2009. doi:10.1016/J.IPL.2009.04.012.
- [3] Alberto Apostolico, Péter L. Erdős, and Alpár Jüttner. Parameterized searching with mismatches for run-length encoded strings. Theoretical Computer Science, 454:23–29, 2012. doi:10.1016/J.TCS.2012.03.018.
- [4] Alberto Apostolico, Péter L. Erdős, and Moshe Lewenstein. Parameterized matching with mismatches. Journal of Discrete Algorithms, 5(1):135–140, 2007. doi:10.1016/J.JDA.2006.03.014.
- [5] Alberto Apostolico and Raffaele Giancarlo. Periodicity and repetitions in parameterized strings. Discrete Applied Mathematics, 156(9):1389–1398, 2008. doi:10.1016/J.DAM.2006.11.017.
- [6] Brenda S. Baker. A program for identifying duplicated code. In Computing Science and Statistics: Proceedings of the 24th Symposium on the Interface, 1992.
- [7] Brenda S. Baker. A theory of parameterized pattern matching: Algorithms and applications. In Proceedings of the 25th Annual ACM Symposium on Theory of Computing (STOC), pages 71–80, 1993. doi:10.1145/167088.167115.
- [8] Brenda S. Baker. Parameterized duplication in strings: Algorithms and an application to software maintenance. SIAM Journal on Computing, 26(5):1343–1362, 1997. doi:10.1137/S0097539793246707.
- [9] Brenda S. Baker. Parameterized diff. In Proceedings of the 10th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 854–855. SIAM, 1999. URL: http://dl.acm.org/citation.cfm?id=314500.314968.
- [10] Richard Beal and Donald A. Adjeroh. Compressed parameterized pattern matching. Theor. Comput. Sci., 609:129–142, 2016. doi:10.1016/J.TCS.2015.09.015.
- [11] Pierre Bourhis, Aaron Boussidan, and Philippe Gambette. On distances between words with parameters. In 34th Annual Symposium on Combinatorial Pattern Matching, CPM 2023, volume 259 of LIPIcs, pages 6:1–6:23, 2023. doi:10.4230/LIPIcs.CPM.2023.6.
- [12] Aaron Boussidan. Comparaison automatique de pièces de théâtre à l’aide de distances d’édition et d’alignement. Phd dissertation, Gustave Eiffel University, 2025.
- [13] Richard Cole, Carmit Hazay, Moshe Lewenstein, and Dekel Tsur. Two-dimensional parameterized matching. ACM Transactions on Algorithms, 11(2):12, 2014.
- [14] S. Deguchi, F. Higashijima, H. Bannai, S. Inenaga, and M. Takeda. Parameterized suffix arrays for binary strings. In Proceedings of the Prague Stringology Conference, pages 84–94, 2008.
- [15] Arnab Ganguly, Wing-Kai Hon, Kunihiko Sadakane, Rahul Shah, Sharma V. Thankachan, and Y. Yang. Space-efficient dictionaries for parameterized and order-preserving pattern matching. In 27th Annual Symposium on Combinatorial Pattern Matching (CPM 2016), volume 54 of Leibniz International Proceedings in Informatics (LIPIcs), pages 2:1–2:12. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2016. doi:10.4230/LIPIcs.CPM.2016.2.
- [16] Arnab Ganguly, Rahul Shah, and Sharma V. Thankachan. pBWT: Achieving succinct data structures for parameterized pattern matching and related problems. In Proceedings of the Twenty-Eighth Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 397–407. SIAM, 2017. doi:10.1137/1.9781611974782.25.
- [17] R. Garg, R. Prasad, and S. Agarwal. Fast parameterized word matching on compressed text. In International Conference on Computer and Communication Technology (ICCCT), pages 317–321. IEEE, 2014.
- [18] Carmit Hazay, Moshe Lewenstein, and Dina Sokol. Approximate parameterized matching. ACM Transactions on Algorithms, 3(3):29, 2007. doi:10.1145/1273340.1273345.
- [19] Richard M. Karp and Michael O. Rabin. Efficient randomized pattern-matching algorithms. IBM J. Res. Dev., 31(2):249–260, 1987. doi:10.1147/RD.312.0249.
- [20] Orgad Keller, Tsvi Kopelowitz, and Moshe Lewenstein. On the longest common parameterized subsequence. Theoretical Computer Science, 410(51):5347–5353, 2009. doi:10.1016/J.TCS.2009.09.011.
- [21] R. Khetan, S. Agarwal, and R. Prasad. An efficient approach towards compressed parameterized word matching using wavelet tree. Journal of Information and Optimization Sciences, 37(2):285–301, 2016.
- [22] I. Lee, J. Mendivelso, and Yoan J. Pinzón. -parameterized matching. In String Processing and Information Retrieval (SPIRE), volume 5280 of LNCS, pages 236–248, 2008.
- [23] Moshe Lewenstein. Parameterized matching. In Encyclopedia of Algorithms, pages 635–638. Springer, 2008. doi:10.1007/978-0-387-30162-4_282.
- [24] Juan Mendivelso, Sharma V. Thankachan, and Yoan J. Pinzón. A brief history of parameterized matching problems. Discrete Applied Mathematics, 274:103–115, 2020. doi:10.1016/J.DAM.2018.07.017.
- [25] Tetsuo Shibuya. Generalization of a suffix tree for RNA structural pattern matching. Algorithmica, 39(1):1–19, 2004. doi:10.1007/S00453-003-1067-9.
Appendix A Proof of Correctness for the Offset Sets
The following is the proof of Lemma 13.
Proof.
Direction ().
Suppose . There exists a bijection such that for all . This implies that for every , the absolute positions of in are identical to the absolute positions of in . Consequently, they share the same start position and the same offset set. Thus, the multiset of offset sets at every position remains invariant, and .
Direction ().
Suppose . We must construct a valid bijection .
A valid bijection must map a character to a character if and only if they are structurally identical. Structural identity requires two conditions:
-
1.
They have the same Offset Set (relative spacing).
-
2.
They have the same Start Position (absolute placement).
Let denote the number of distinct characters in string that start at position and have offset set . To prove a bijection exists, it is sufficient to show that for all positions and all offset sets :
If this equality holds, we can map the characters of type in arbitrarily to the characters of type in . Computing from the Representation: We show that is uniquely determined by the sequence of multisets . For any position and offset set , let be the multiplicity of in the multiset . A character contributes to the count of at position if:
-
1.
.
-
2.
appears at . This happens if started at some position such that .
We can express the total count at position as the sum of characters starting now () and characters that started earlier () and are re-appearing:
Rearranging to solve for the current starts:
Inductive Argument.
We prove for all by strong induction.
-
Base Case (): There are no offsets relative to 1. Thus . Since , the counts are identical, so .
-
Inductive Step: Assume for all . In the equation for :
-
–
is identical because .
-
–
The summation terms involve indices strictly less than . By the induction hypothesis, these terms are identical for and .
Therefore, .
-
–
Since the number of characters for every specific (Start Position, Offset Set) pair is identical, we can construct a perfect bijection .
Appendix B Proof of Theorem 2
Theorem 28 (Complexity of Comparison Algorithm).
Let and denote the total size (number of character occurrences) of the two set-strings. Algorithm 1 runs in time and uses space .
Proof.
Time Analysis.
-
Initialization: Selecting primes and initializing tables takes time.
-
Offset Set Computation: By Lemma 19, computing the offset sets requires iterating through every character occurrence in both strings exactly once. The time required is .
-
Layer 1 Hashing: We calculate for every character . The cost of computing the hash for a specific offset set is proportional to its size . Since the sum of the sizes of all offset sets is exactly the total number of character occurrences, the total time is .
-
Layer 2 Hashing: We calculate for every position . The cost at position is proportional to the number of characters in the set at that position, (or ). Summing over all positions , the total time is .
-
Comparison: Comparing the two mashed sequences takes time, which is dominated by since .
Since the total running time is .
Space Analysis.
Storing the offset sets and the intermediate hash values requires space proportional to the total number of elements in the sets, which is .
Appendix C Proof of Complexity Analysis
Proof.
Time Complexity.
-
1.
Preprocessing: Building the occurrence lists takes . Computing the initial pattern hash takes .
-
2.
Sliding Window Scan: The loop runs for steps. Inside the loop, the “Global Shift” (Step 2) takes time. The “Isolate” (Step 1) and “Reintegrate” (Step 3) phases iterate only over the set of active characters . Let be the number of operations at step . We have . Summing over all windows:
Observe that each character occurrence in the text at position appears in the set exactly once (when it leaves the window) and in the set exactly once (when it enters the window). Therefore:
-
3.
Hash Updates: All internal hash updates (multiplications, additions) and list lookups (finding next occurrence ) take time.
Thus, the total time complexity is .
Space Complexity.
The occurrence lists store every character position, requiring space. The hash maps for and store one entry per unique character currently in the window. Since the number of unique characters cannot exceed the number of character occurrences, this is bounded by . The pattern storage takes . Thus, the total space is .
