Abstract 1 Introduction 2 Preliminaries 3 Strong Periodicity 4 Weak Periodicity 5 Lower Bounds for Weak Periodicity Testing References Appendix A Probability Inequalities Used in This Work Appendix B Omitted Proofs

Periodicity Property Testing
on Strings with Wildcards

Carl Barton ORCID Birkbeck, University of London, UK    Panagiotis Charalampopoulos ORCID King’s College London, UK    Taha El Ghazi ORCID DIENS, École normale supérieure de Paris, PSL Research University, France    Jonas Ellert ORCID CWI, Amsterdam, The Netherlands    Oded Lachish ORCID Birkbeck, University of London, UK    Tatiana Starikovskaya ORCID DIENS, École normale supérieure de Paris, PSL Research University, France
Abstract

In this work, we study periodicity in strings with wildcards. A string T with at most k wildcards is called strongly (p,k)-periodic if the wildcards in T can be replaced with alphabet symbols to obtain a string with period p, and weakly (p,k)-periodic if T[i] matches T[i+p] for all i. Intuitively, both generalize to (g,k)-periodicity, which is the property of being (p,k)-periodic for some p[1..g].

An ε-tester for a property 𝒫 is an algorithm that distinguishes between strings that satisfy 𝒫 and strings where one needs to change at least an ε-fraction of the symbols to obtain a string that satisfies 𝒫. We study one-sided error testers, where strings satisfying 𝒫 must always be accepted, while strings that are ε-far must be rejected with probability at least 2/3. The complexity of a tester is the worst-case number of symbols of an input of length n it must read to make the decision.

We design the following testers for p,gn/2:

  1. 1.

    An ε-tester for strong (p,k)-periodicity with complexity 𝒪~ε(1) 111Hereafter, 𝒪~ε and Ω~ε means that we hide factors polylogarithmic in n,k,g and polynomial in ε..

  2. 2.

    An ε-tester for strong (g,k)-periodicity with complexity 𝒪~ε(g).

  3. 3.

    An ε-tester for weak (p,k)-periodicity with complexity 𝒪~ε(min(k,nk+p)).

  4. 4.

    An ε-tester for weak (g,k)-periodicity with complexity 𝒪~ε(min(k+gk,nk)).

Additionally, we show a lower bound on the complexity of ε-testers for weak (g,k)-periodicity, implying that our tester for weak (g,k)-periodicity is optimal up to a multiplicative (ε1log(gk))𝒪(1) factor for a wide range of g and k. Finally, our tester for strong (g,k)-periodicity generalizes the one of [Lachish and Newman; Algorithmica 2011] for strings without wildcards, matching (up to polylogarithmic factors) the unconditional lower bound of Ω~(g) in said work for constant ε.

Keywords and phrases:
periodicity, property testing, wildcards
Copyright and License:
[Uncaptioned image] © Carl Barton, Panagiotis Charalampopoulos, Taha El Ghazi, Jonas Ellert, Oded Lachish, and
Tatiana Starikovskaya; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Probabilistic computation
; Mathematics of computing Combinatorics on words
Funding:
Parts of the presented ideas were conceived during a research visit funded by a Royal Society International Exchanges Award. Taha El Ghazi, Jonas Ellert, and Tatiana Starikovskaya were partially funded by grant ANR20-CE48-0001 from the French National Research Agency. Jonas Ellert was partially supported by an ERCIM Alain Bensoussan fellowship.
Editors:
Philip Bille and Nicola Prezza

1 Introduction

In this work, we study property testers for periodicity in the presence of wildcards. An ε-tester is an algorithm that, given an input string, must decide whether it satisfies a given property, while querying as few symbols of the input as possible. Often, it is impossible to make an exact decision without querying the entire input; instead, one wants to distinguish between strings that have the property and those that are far from having the property, where far means that one has to change an ε-fraction of the symbols of the input to obtain a string satisfying the property (for a given ε). The tester does not access the input directly and instead uses oracle queries of the form: what is the symbol at a given position? The number of queries a tester makes is referred to as its complexity. We study one-sided error testers, which always accept strings satisfying the property, while rejecting strings that are ε-far from having the property with probability at least 2/3.

A string T[0..n) without wildcards has a period p if T[i]=T[i+p] for all i[0..np). Property testing for periodicity in such strings has been previously studied in [9, 10] and [15]. Ergün et al. [9, 10] studied the problem using three generalizations of periodicity that lead to different interpretations of approximate periodicity. They show that the resulting definitions of approximate periodicity are constant approximations of each other and that it is possible to distinguish between the case when T has an ε-approximate period p[1..n2] and T is ε-far from having a period p[1..n2] using 𝒪(npolylogn) queries, even for constant ε. Lachish and Newman [15] showed a property tester that decides whether a string has a period pn/2 and has complexity 𝒪(1/ε). They further showed that, to decide whether there is a period p[1..g] for gn/2, it suffices to query 𝒪(ε1glogg) symbols.

In this work, we focus on strings with wildcards. A wildcard, denoted by , matches all symbols from the alphabet, intuitively representing a symbol whose exact value is irrelevant or unavailable. We consider two natural extensions of the notion of periodicity to strings containing wildcards: strong periodicity and weak periodicity.

A string T[0..n) with at most k wildcards is said to have a strong period (p,k) if there exists a wildcard-free string T[0..n) that matches T and has period p. Equivalently, T has a strong period (p,k) if its wildcards can be replaced by alphabet symbols so that the resulting string T satisfies T[i]=T[i+p] for all i[0..np).

For weak periodicity, we relax this requirement: we say that T has a weak period (p,k) if T[i]T[i+p] for all i[0..np), where ab if and only if a=b or at least one of a and b is a wildcard. For example, xxxyy is weakly (1,1)-periodic (but not strongly). Both notions of periodicity with wildcards have previously been studied extensively in the context of generalizing the Fine–Wilf periodicity lemma [11]; see [2, 3, 4, 5, 6, 7, 19, 14, 18, 20].

Our 𝜺-testers.

For a string T[0..n), integers pn/2, gn/2, and k, and a value ε, we design the following testers:

  1. 1.

    An ε-tester for strong (p,k)-periodicity with complexity 𝒪(ε2); for kεn/32, we achieve complexity 𝒪(ε1). See Lemma 9.

  2. 2.

    An ε-tester for strong (g,k)-periodicity with complexity 𝒪(ε1glogg); for kεn/32, we achieve complexity 𝒪(ε1/2glogg). See Lemma 10.

  3. 3.

    An ε-tester for weak (p,k)-periodicity with complexity 𝒪~ε(min(k,nk+p)). See Corollary 23.

  4. 4.

    An ε-tester for weak (g,k)-periodicity with complexity 𝒪~ε(min(k+gk,nk)). See Corollary 24.

The starting point of our testers is a conceptual partition of the input string T into equivalence classes for a fixed period p. Each equivalence class is a subsequence of T consisting of the symbols of T whose positions are in the same class modulo p. If T is strongly (p,k)-periodic, then every equivalence class must be unary. Intuitively, a witness against strong periodicity is a pair of positions in an equivalence class in which the symbols do not match. On a very high level, we show that for far instances the number of such witnesses is large, which allows detecting them with a few queries. For weakly (p,k)-periodic strings, every equivalence class contains at most k+1 maximal unary factors separated by wildcards. Here, a witness consists of k+1 non-matching pairs that do not overlap. Intuitively, each wildcard can “fix” one such pair (for example, consider abc which is weakly (1,2)-periodic and has two such pairs), but we would need k+1 wildcards to fix k+1 non-overlapping non-matching pairs, which we simply do not have. To show that the number of such witnesses in far instances is large, we demonstrate that a far instance can be decomposed into k+1 factors, where each factor is far from unary. We then need to find one non-matching pair in each factor, which can be done with a few queries.

Lower bounds.

Lachish and Newman [15] showed a lower bound on the complexity of testers for periodicity on strings without wildcards. Namely, they showed that every 1/32-tester for (g,0)-periodicity must query Ω(g/logn) symbols of the input, for every g. This implies that, for constant k and ε, the tester in Lemma 10 is optimal up to polylogarithmic factors.

Finally, in Theorem 31, we show a lower bound on the complexity of testers for weak (g,k)-periodicity. In a simplified form, it states that any 1/64-tester for weak (g,k)-periodicity has complexity Ω~(min(gk,max(n,nk))). In the regime when g and k are sufficiently small, for example, when g,kn, our tester for weak (g,k)-periodicity (Corollary 24) matches this bound up to polylogarithmic factors.

Other related work.

Awofeso et al. [1] studied property testing for quasiperiodicity. The quasiperiodicity studied in this work is a cover, where they presented an algorithm that can decide if a string has a cover of length q using 𝒪(ε1q3logq) queries. Chan et al. [8] and then Jin and Kociumaka [13] studied property testers for pattern matching.

2 Preliminaries

For integers i,j, we write [i..j]=[i..j+1)=(i1..j]=(i1..j+1) to denote {k:ikj}, and [i] to denote [0..i). Let Primes denote the set of prime numbers.

An alphabet Σ is a finite set whose elements are called symbols. We consider a special symbol Σ called a wildcard and denote Σ{} by Σ. For two symbols a,bΣ we say that a matches b and write ab if either a,bΣ and a=b, or at least one of a and b is a wildcard. Otherwise, we say that a and b do not match and write a≇b.

A length-n string T over an alphabet Σ is a sequence of n symbols from Σ. We write T[0..n) to denote that T is a string of length |T|=n. For i,j[0..n), we write T[i] to denote the i-th symbol in T, and T[i..j]=T[i..j+1)=T(i1..j]=T(i1..j+1) to denote the sequence T[i]T[i+1]T[j] if ij, and the empty string ε otherwise. T[i..j] is called a factor of T. We say that T is a k-wildcard string if it contains at most k wildcards.

Consider two strings T1,T2Σn. We say that T1 and T2 match and write T1T2 if, for all i[n], T1[i]T2[i].

Strong and weak periods.

We now give formal definitions of strong and weak periods of strings containing wildcards. Intuitively, a string is strongly periodic if we can replace all its wildcards with symbols from Σ to obtain a periodic string in Σ.

Definition 1 (Strongly periodic string).

Let T[0..n)Σ, k[0..n], and p[n]. We say that T is strongly (p,k)-periodic or that T has a strong period (p,k) if T contains at most k wildcards and there is a string QΣp such that TQ[0..n), where Q is an infinite string obtained by concatenating infinitely many copies of Q.

Weak periodicity is a more relaxed notion that, intuitively, allows wildcards to act as transition points.

Definition 2 (Weakly periodic string).

Let T[0..n)Σ, k[0..n], and p[n]. We say that T is weakly (p,k)-periodic or that T has a weak period (p,k) if and only if T contains at most k wildcards and T[0..np)T[p..n).

Property testers.

In the property testing model, the goal is to decide whether the input has a certain property or is far from having it by querying as few of the input symbols as possible. We next formalize what it means for a string to be far from having some property.

Definition 3 (ε-far).

We say that a string T is ε-far from having a property 𝒫 if one needs to change at least ε|T| symbols of T to obtain a string that has property 𝒫.

Definition 4 (Property tester).

A one-sided ε-property tester for a property 𝒫 is an algorithm that receives as an input a string T and:

  • returns “yes” if T satisfies the property 𝒫 with probability 1,

  • returns “no” with probability at least 2/3 if T is ε-far from satisfying the property,

  • returns “yes” or “no” otherwise.

In this work, we focus on non-adaptive property testers, meaning that the symbols to query are selected offline, i.e. the, position of the i-th queried symbol does not depend on the first i1 queried symbols. Consistent with the literature, we define the complexity of a tester as the number of symbols of the input string that they query in the worst case.

Structure of strings with wildcards.

Before describing periodicity property testers, we first introduce additional notation used throughout the paper. For analyzing whether a string T[0..n) is (p,k)-periodic for some p and k, we define the following strings T0,,Tp1: for i[n], we have Timodp[i/p]=T[i], i.e., Tj is obtained by restricting T to positions equivalent to j(modp). We refer to strings T0,,Tp1 as equivalence classes.

We will analyze (factors of) equivalence classes via symbol frequencies. For any string SΣ and any symbol sΣ, we define #S(s) to be the number of occurrences of s in S. If sΣ, then we further define #S(s¯)=|S|#S(s)#S(), i.e., the number of occurrences of symbols that are neither s nor . The majority symbol of S is sΣ that maximizes #S(s); if multiple symbols satisfy this definition, then we choose the one that occurs first in S. For this uniquely defined majority symbol s, we write #S+=#S(s) and #S=#S(s¯). All other symbols are called minority symbols.

Proposition 5.

For every string SΣ, there is a bipartition A,B of Σ such that sA#S(s)#S/2 and sB#S(s)max{#S/2,(|S|#S())/2}.

Proof.

Let s be the majority symbol of S. We start with empty sets A and B and process the symbols in Σ{s} in an arbitrary order. We add each symbol we encounter to the set that currently contributes fewer positions to S. Clearly, at any point in time, the terms sA#S(s) and sB#S(s) differ by at most #S+. We assume, without loss of generality, that in the end we have b:=sB#S(s)a:=sA#S(s), meaning that a#S/2. Finally, we insert s to B. Then, we have sB#S(s)=b+#S+a#S/2, which concludes the proof since sB#S(s)a and a+sB#S(s)=|S|#S() imply that sB#S(s)max{#S/2,(|S|#S())/2}.

3 Strong Periodicity

We start by introducing the notion of witnesses of strong non-periodicity.

Definition 6 (Witnesses).

Let TΣn, and p1. We say that (i,j)[n]2 is a p-witness if ji(modp) and T[i]≇T[j]. We denote the set of all p-witnesses of T by Wp(T).

Observation 7.

A string TΣn is strongly (p,k)-periodic if and only if it is a k-wildcard string and Wp(T)=.

In strings that are far from periodic the number of p-witnesses is large:

Lemma 8.

Let k[n] and TΣn be a k-wildcard string that is ε-far from being strongly (p,k)-periodic. We have |Wp(T)|ε2n22p. Further, if kεn/32, then |Wp(T)|εn216p.

Proof.

Case I (unbounded 𝒌).

There are at least εn positions i[0..n) such that T[i]Σ and T[i] is a minority symbol of Timodp. Otherwise, we could simply replace each minority symbol to obtain a strongly (p,k)-periodic string, contradicting the fact that T is ε-far. Let us fix such a position i, and set s:=T[i] and j:=imodp. Our fixed symbol can be paired with each symbol from Σ{s} in Tj to give a witness pair, and the number of such symbols is #Tj+#Tj+#Tj(s)#Tj. In particular, by summing over all minority symbols from Σ, we conclude that each equivalence class contributes at least (#Tj)2/2 unordered pairs, resulting in (#Tj)2/2 p-witnesses (where we divide by 2 to avoid double-counting). Then, by the Cauchy–Schwarz inequality, we have j=0p1(#Tj)2/2(j=0p1#Tj)2/(2p)ε2n2/(2p).

Case II (𝒌𝜺𝒏/𝟑𝟐).

The bound on k implies that there are εp/8 classes with n/(4p) wildcards. The combined length of these classes is εp/8n/pεn/4. We claim that there are 3εn/4 positions i[0..n) such that T[i]Σ is not the majority symbol of Timodp and #Timodp()<n/(4p). Otherwise, we could simply overwrite the at most εp/8 classes that have n/(4p) wildcards with unary strings, using εn/4 substitutions, and then replace the minority symbols in the remaining classes with the majority symbol using another <3εn/4 substitutions. This contradicts that T is ε-far from being strongly (p,k)-periodic. Among the at least 3εn/4 positions specified above, fix a position i, and let s:=T[i] and j:=imodp. The symbol s can be paired with every symbol from Σ{s} in Tj to give a p-witness. The number of such symbols is |Tj|#Tj()#Tj(s)n/pn/(4p)n/(2p)n/(4p). Thus, in total, we have 3εn/4(n/(4p))/2εn216p p-witnesses (we have again divided by 2 to avoid double-counting).

3.1 Strong Periodicity Testers

We now show testers for strong periodicity.

Algorithm 1 A strong (p,k)-periodicity tester for a fixed candidate period p[1..n2].
Lemma 9.

For all ε(0,1) and p[1..n2], Algorithm 1 is a one-sided ε-property tester for strong (p,k)-periodicity with complexity 𝒪(ε2). The complexity is 𝒪(ε1) if kεn/32.

Proof.

The algorithm never returns “no” if it receives a strongly (p,k)-periodic string by Observation 7. Next, consider a k-wildcard string TΣn that is ε-far from being strongly (p,k)-periodic. Since the number of pairs (x,y)[n]2 such that xy(modp) is at most n2p, the probability that a randomly selected pair belongs to Wp(T) is at least |Wp(T)|n2/p. Hence, the probability that our algorithm returns “yes” is at most (1|Wp(T)|/(n2/p))rexp(r|Wp(T)|/(n2/p))e21/3, where the penultimate step is due to Lemma 8.

We now generalize the algorithm to test for strong (g,k)-periodicity. A key observation from the algorithm above is that roughly p/(ε2n) independent pairs of positions suffice to discover a p-witness. By sampling around g/(ε2n) positions, we can still form roughly g/(ε2n)p/(ε2n) pairs. By slightly increasing the sampling rate, we can account for the fact that the pairs are not entirely independent, and also boost the success probability enough to succeed for all p[1..g] with high enough probability. This results in the lemma below, whose proof is provided in Appendix B.

Algorithm 2 A strong (g,k)periodicity tester for g[2..n2].
Lemma 10.

For g[2..n2] and ε(lngg)1/6, Algorithm 2 is a one-sided ε-property tester for strong (g,k)-periodicity with complexity 𝒪(ε1glogg).

If kεn/32, for g[2..n2] and ε(lngg)1/3, Algorithm 2 is a one-sided ε-property tester for strong (g,k)-periodicity with complexity 𝒪(ε1/2glogg).

 Remark 11.

For constant g, Lemma 10 requires that ε is at least constant. However, in this case, we can obtain a tester for small g and arbitrary ε by simply invoking Lemma 9 for each p[1..g] (a few times to ensure that the error probability does not blow up).

4 Weak Periodicity

We first introduce the notion of witnesses for weak periodicity. For Lemma 14 below, we essentially apply Proposition 5 to each class of T that does not contain too many wildcards.

Definition 12.

Let TΣ be a k-wildcard string and p[1..n2].

  • A p-witness is a pair (a,b) such that ab(modp) and T[a]≇T[b].

  • An explicit p-witness is a p-witness (a,b) such that b=a+p.

  • An implicit p-witness is a set of k+1 pairs {(a0,b0),,(ak,bk)} such that

    • for each i[0..k], either ai=bi and T[ai]=T[bi]=, or (ai,bi) is a p-witness, and

    • for each distinct i,j[0..k], if aiaj(modp) then [ai..bi)[aj..bj)= (disjointness condition).

Lemma 13.

Weakly (p,k)-periodic strings admit neither explicit nor implicit p-witnesses.

Proof.

Assume that some string T is weakly (p,k)-periodic. In this case, it does not contain explicit p-witnesses because T[i]T[i+p] for all i. Furthermore, assume towards a contradiction that there exists an implicit p-witness {(a0,b0),,(ak,bk)}. For every (ai,bi) such that ai=bi and T[ai]=T[bi]=, we obviously have T[mi]= for mi:=ai. For every (ai,bi) which is a p-witness, there exists mi(ai..bi) with miai(modp) and T[mi]= (as otherwise the class Taimodp cannot be weakly 1-periodic). By the disjointness condition, all mi are distinct, and hence T contains k+1>k wildcards, a contradiction.

Lemma 14.

For kεn/16, consider a k-wildcard string TΣn and p[1..n2]. If T is ε-far from being weakly (p,k)-periodic, then there is a set J[0..p) and, for each jJ, sets Aj,Bj[0..|Tj|) satisfying:

  • for every jJ and (a,b)Aj×Bj, Tj[a]≇Tj[b];

  • jJ|Aj|εn/4, and, for every jJ, |Bj|n/(8p);

  • if each position in [n] is sampled independently with probability rp/(2n), the sample hits Aj (resp. Bj) independently with probability at least r|Aj|/2 (resp. r|Bj|/2).

Proof.

Consider the equivalence classes T0,,Tp1. For each j, define the set Mj[0..|Tj|) to contain the positions corresponding to the minority symbols of Tj, i.e., |Mj|=#Tj. We have j=0p1|Mj|εn. Otherwise, we could merely replace all minority symbols with the majority ones to obtain a (p,k)-periodic string, contradicting the fact that T is ε-far. Let J[0..p) be the set containing exactly the indices j[0..p) such that Tj contains at most n/(4k) wildcards. Note that there are at most 4kp/n classes that contain more than n/(4k) wildcards and they contribute at most 4kp/nn/p8kεn/2 minority elements. Furthermore, |J|p4kp/np/2 (where the second step is due to k<n/8). We have shown that jJ|Mj|εn/2. For each class Tj with jJ, by Proposition 5, we can bipartition its positions into sets Aj and Bj of sizes |Aj||Mj|/2 and |Bj|(|Tj|n/(4p))/2n/(8p) such that every pair in Aj×Bj yields a mismatch in Tj. For the final point, all sets are disjoint and thus hit independently. We observe that |Aj||Tj|n/(2p). Hence, r|Aj|1. The probability of not missing Aj is at least 1(1r)|Aj|r|Aj|1+r|Aj|r|Aj|/2 (using 1xex1/(1+x)). The proof for Bj is symmetric.

4.1 Testing Weak (𝒑,𝒌)-Periodicity Through Implicit Witnesses

We start with testers for a fixed period p.

Algorithm 3 A weak (p,k)-periodicity tester for fixed large period p.
Lemma 15.

For p>2560k/ε, Algorithm 3 is a non-adaptive one-sided error ε-tester for weak (p,k)-periodicity with complexity 𝒪(ε1k).

Proof.

Observe that the algorithm only returns “no” if it finds an implicit p-witness. By Lemma 13, a weakly (p,k)-periodic string contains no implicit p-witness; thus, the tester has one-sided error, i.e., it answers “yes” for every weakly (p,k)-periodic string.

Now, assume that T is ε-far from being weakly (p,k)-periodic. If the algorithm answers “yes”, then at least one of the following holds:

  • the algorithm samples more than 2rn positions in the first stage;

  • the set of sampled positions does not contain an implicit p-witness.

The probability of the first event is at most exp(rn/3)exp(400)<0.01 via a Chernoff bound (Fact 33 invoked with δ=1). We only query the input if |I|2rn and thus |II|4rn. Hence, the complexity is as claimed. For the second event, we show that, with constant probability, we find k+1 (non-explicit) p-witnesses in k+1 different equivalence classes. These pairs form an implicit p-witness.

We use the construction from Lemma 14, consisting of J[0..p) and, for jJ, sets Aj,Bj such that Tj[a]≇Tj[b] for every (a,b)Aj×Bj. Since we sample with rate rp/(2n), by Lemma 14, we expect to hit each set Aj independently with probability at least r|Aj|/2. If we hit Aj, then we also sample another position from the same equivalence class in the second stage. This position is in Bj with probability at least |Bj|/|Tj|1/16 due to Lemma 14. Hence, with probability at least r|Aj|/32, we hit both Aj and Bj.

Finally, the expected number of jJ for which we succeed, i.e., for which we hit both Aj and Bj and thus find a witness pair, is at least μj=0p1r|Aj|32rεn128=10k, where the middle step follows from Lemma 14. Since each j succeeds independently, we can apply a Chernoff bound (Fact 33) with δ=9/10 to show that we succeed for less than k+1 classes with probability at most 2exp(δ2μ/3)2exp(2.7k)0.15. Otherwise, the at least k+1 discovered pairs constitute an implicit witness. Finally, using the union bound for the two sources of error, we answer “yes” for an ε-far instance with probability 0.16<1/3.

In the approach above, we guarantee that the p-witnesses are disjoint by finding them in distinct equivalence classes. Hence, the approach becomes unsuitable for small p. For example, if pk, then we have to find multiple witnesses in one equivalence class.

We propose a different approach for small p. In this case, let c1 and assume that pck/ε, and kε2n/(8c). We introduce the following factorization scheme that will be used to detect witness pairs: first, we split T[0..n) into equivalence classes T0,,Tp1, and then we read and factorize each Tj from left to right. Assume that we have already factorized Tj[0..i). The next factor is Tj[i..i+), where is the minimal value such that either i+=|Tj| or #Tj[i..i+)ε2n/(8ck)1. Hence, each factor is the shortest prefix of the remaining string that has exactly ε2n/(8ck) occurrences of minority symbols. Further, we call a factor with exactly ε2n/(8ck) occurrences of minority symbols a complete factor. This factorization only serves the proof and is not actually computed.

Lemma 16.

If T is ε-far from being weakly (p,k)-periodic, then T has at least k+1 complete factors over all the equivalence classes, assuming that pck/ε and kε2n/(8c) for some c1.

Proof.

We first show that T has at least p+k+1 factors. If T has at most p+k factors, we can obtain a weakly (p,k)-periodic string with εn substitutions as follows. We first substitute all minority symbols of each factor with its majority symbol. Since ε2n/(8ck)1, we have ε2n/(8ck)ε2n/(4ck). Hence, substituting the minority symbols requires at most

(p+k)ε2n/(4ck)(ck/ε+k)ε2n/(4ck)2ck/εε2n/(4ck)εn/2

substitutions. We perform another k substitutions to replace each wildcard with the majority symbol of its surrounding factor. Afterwards, each factor is over a unary alphabet. Since there are at most p+k factors, and each of the p equivalence classes contributes at least one factor, there are only k boundaries between factors. For each boundary, we perform one substitution to make one of the boundary symbols into a wildcard. As a result, the entire string is weakly (p,k)-periodic. The total number of substitutions is at most εn/2+2kεn. Hence, T has at least p+k+1 factors, and thus at least k+1 complete factors.

Algorithm 4 A weak (p,k)-periodicity tester for fixed small period p.
Lemma 17.

Let c1. For pck/ε, and kε2n/(8c), Algorithm 4 is a non-adaptive one-sided error ε-tester for weak (p,k)-periodicity with complexity 𝒪(cklogk/ε2).

Proof.

Since we only answer “no” if we find an implicit p-witness, we always answer “yes” for periodic instances due to Lemma 13. Assume now that T is ε-far from being weakly (p,k)-periodic. Consider a complete factor of T. By Lemma 16, there are k+1 of those. By Proposition 5 there is a bipartition A, B of the alphabet such that the symbols of A (resp. B) correspond to a set of at least ε2n/(16ck) positions of the factor. Crucially, if we pair up any position with a symbol from A with any position with a symbol from B, we obtain a witness pair. Furthermore, since factors in the same equivalence class do not overlap, a set of k+1 witness pairs over the k+1 different factors forms an implicit witness. As a result, if the algorithm answers “yes”, then at least one of the following holds:

  • the algorithm samples more than 2rn positions;

  • the algorithm misses a witness pair in at least one of the complete factors.

The probability of the first event is at most exp(rn/3)exp(16ln40/3)<0.01 via a Chernoff bound (Fact 33 invoked with δ=1). We only query the input if |I|2rn, and thus the complexity is as claimed. The probability of not sampling a position corresponding to a symbol in A (analogously in B) in a fixed factor is at most (1r)ε2n/(16ck)erε2n/(16ck)=1/(20(k+1)). Hence, by the union bound, we fail for at least one factor with probability at most 0.1. Combining the two sources of failure by the union bound, we answer “yes” for a far instance with probability at most 0.2.

4.2 Testing Weak (𝒈,𝒌)-Periodicity Through Implicit Witnesses

We now present a tester for weak (g,k)-periodicity which uses implicit witnesses.

Algorithm 5 A tester for weak (g,k)-periodicity for small g.
Lemma 18.

Let c1. For gck/ε and kε2n/(8c), Algorithm 5 is a non-adaptive one-sided error ε-tester for weak (g,k)-periodicity with complexity 𝒪(cklog(gk)/ε2).

Proof.

The analysis is similar to that of Algorithm 4, but with a higher sampling rate. By Lemma 13, the algorithm answers “yes” for strings that have a weak period p[1..g].

Otherwise, i.e., for an input that is ε-far from being weakly (g,k)-periodic, the algorithm only answers “yes” if it samples more than 2rn indices, or if, for a certain pg, it does not find a witness pair in at least one complete factor. The first event occurs with probability at most exp(rn/3)exp(16ln40/3)<0.01 via a Chernoff bound (Fact 33 invoked with δ=1). For a fixed pg and a fixed complete factor, the second event occurs with probability at most 1/(20(k+1)g) (via the same calculation as in Lemma 17). Therefore, over all g possible periods and their 2(k+1)g sets of positions, the union bound implies that we fail for at least one set with probability at most 0.1. If T is indeed ε-far from being weakly g-periodic, and thus also from being weakly (p,k)-periodic for every p[1..g], then with probability at least 0.8 we can report a witness for every p.

Algorithm 6 A tester for weak (g,k)-periodicity for g[1..n2].
Lemma 19.

For kε2n/(84096+(lng)/k), Algorithm 6 is a non-adaptive one-sided error ε-tester for weak (g,k)-periodicity with complexity 𝒪(log2g/ε2+klog(gk)/ε2+g(k+logg)/ε).

Proof.

We only answer “no” if both of the following events occur: Algorithm 5 returns “no” at least once (which by Lemma 18 implies that T has no period g), and we find an implicit p-witness for every period p(g..g]. Hence, we never return “no” if the input string is weakly (g,k)-periodic. It remains to handle strings that are ε-far from all periods in [1..g]. We have to show that we accept them with probability at most 2/3.

First, by Lemma 18, if T is ε-far from being weakly (g,k)-periodic, then the probability of all three calls to Algorithm 5 returning “yes” is 1/33<0.05. The number of queries is 𝒪(ckln(gk)/ε2)=𝒪(ckln(gk)/ε2), which is bounded by 𝒪((ln2g)/ε2) if k=𝒪(lng); otherwise, c=𝒪(1) and hence the number of queries is 𝒪(kln(gk)/ε2).

We next bound the probability of sampling at least 2rn indices. This happens with probability at most exp(rn/3)exp(q/6)<exp(4096/6)<0.01 via a Chernoff bound (Fact 33 with δ=1). We only query the input if the total number of samples is at most 2rn. Hence, the complexity is as claimed.

If we enter the second stage, then let 𝒢p be the event that the algorithm does not find an implicit p-witness. By the union bound, we answer “yes” due to one of these events with probability at most p[q..g]Pr[𝒢p]. Hence, we can conclude the proof by showing that Pr[𝒢p]1/(9g), which implies that we answer “yes” with probability at most 1/9. Then, via the union bound, the error probabilities from all sources sum to 0.05+0.01+1/9<1/3.

From now on, fix any p[q..g]. We perform the analysis with a lower sampling rate r:=pq/(2n)r, which can only lower our success probability. We use the construction from Lemma 14, consisting of J[0..p) and, for jJ, sets Aj,Bj such that Tj[a]≇Tj[b] for every (a,b)Aj×Bj. Due to rp/(2n), by Lemma 14, we expect to hit each set Aj (resp. Bj) independently with probability r|Aj|/2 (resp. r|Bj|/2). For any jJ, we hit both Aj and Bj (and thus discover a witness pair) with probability at least r2|Aj||Bj|/4r2n|Aj|/(32p). The expected number of different j for which we are successful is μj=0p1r2n|Aj|32pr2εn2128p=qε5128k+8lng, where the second step is due to Lemma 14. Finally, applying the Chernoff bound from Fact 33 with δ=7/8, we are successful for at most k+lng(1δ)μ classes with probability at most exp(δ2μ/2)exp(3k3lng)<1/(9g).

4.3 Testing Weak Periodicity Through Explicit Witnesses

Lemma 20.

Consider a k-wildcard string TΣ that is ε-far from being (p,k)-periodic, where kεn/4. There are at least (p+k)ε/8 explicit p-witnesses.

Proof.

At least εp/2 of equivalence classes of T are not weakly (1,k)-periodic. Otherwise we could simply overwrite these classes with unary strings using less than εp/2n/pεn substitution. This would result in a weakly (p,k)-periodic string, which contradicts the fact that T is ε-far. Consequently, εp/2 classes have at least one explicit p-witness each.

We now prove that the number of explicit witnesses exceeds εk/2. To do so, we further greedily factorize each equivalence class from left to right into maximal factors of the form S{s,} for any sΣ. We then obtain a string T without wildcards by replacing each wildcard in T with the symbol of its surrounding factor. This requires kεn/4 substitutions and results in a string T that is 3ε/4-far from being weakly (p,k)-periodic. Furthermore, if T contains k+x explicit witnesses, then T contains at least x explicit witnesses.

Let t be the total number of maximal unary factors over all equivalence classes in T. Since T is 3ε/4-far from being weakly (p,k)-periodic, we have t>k+1, or else it could be made into a weakly (p,k)-periodic string by adding at most k wildcards at factor boundaries. We say that a maximal unary factor is short if it is among the shortest tk>0 maximal unary factors, and long otherwise. We claim that the short factors must contribute at least εn/2 symbols overall. Otherwise, we can again show that 3εn/4 substitutions are sufficient to make T periodic: We replace each symbol of a short factor with the symbol populating the closest long factor in its equivalence class (or with a if such run is undefined). This effectively merges each short factor with a long one. Every remaining run is either an extension of one of the original k long factor, or an equivalence class that consists of a single factor. The total number of long factors in all classes that contain at least two long factors is at most k. Hence, we can fix their at most k boundaries with wildcards. The total number of substitutions is less than εn/2+k3εn/4.

Since short runs contribute εn/2 symbols, there is a short run of length εn/(2t2k). Consequently, all long factors have length at least . The total length of long runs is therefore at least kkεn2t2k. On the other hand, it is upper-bounded by n, which implies kε/2+kt. Hence, the number of explicit p-witnesses in T is at least k+εk/2, which implies that T contains at least εk/2 explicit p-witnesses, concluding the proof.

Algorithm 7 A tester for weak (p,k)-periodicity.

The following two lemmas follow from Lemma 20 in a straightforward manner.

Lemma 21.

Algorithm 7 is a non-adaptive ε-tester for weak (p,k)-periodicity with complexity 𝒪(ε1n/(k+p)).

Proof.

Since weakly (p,k)-periodic strings do not contain explicit p-witnesses (see Lemma 13), they are accepted by Algorithm 7. Consider now a string that is ε-far from being weakly (p,k)-periodic. By Lemma 20, the probability that a given pair sampled by the algorithm is an explicit witness is at least ε(p+k)n. Hence, the probability that the algorithm does not find an explicit witness is at most (1ε(p+k)n)2nε(p+k)e21/3.

Algorithm 8 A tester for weak (g,k)-periodicity.
Lemma 22.

Algorithm 8 is a non-adaptive ε-tester for weak (g,k)-periodicity with complexity 𝒪(nloggεk).

Proof.

First, consider a weakly (p,k)-periodic string for some 1pg. It does not contain an explicit p-witness, and hence is accepted by Algorithm 8. Now, consider a string T that is ε-far from being weakly (p,k)-periodic for all 1pg. Fix one p, 1pg. By Lemma 20, T has at least ε(k+p)/8 explicit p-witnesses. Furthermore, since there are at most 2 explicit p-witnesses sharing the same index, there are at least ε(k+p)/16 explicit witnesses that are mutually disjoint. Let X be the number of these explicit p-witnesses sampled by the algorithm. X is a sum of independent indicator random variables, and therefore we have

Pr(X=0)(1r2)ε(k+p)/16er2ε(k+p)=e(k+p)ln(100g)/k1100g.

Hence, by the union bound, the probability that the algorithm misses an explicit witness for at least one p such that T is ε-far is at most 0.01. Furthermore, by Fact 33 invoked with δ=9, the probability that the algorithm samples more than 10rn positions is at most 0.01. By the union bound, the probability that the algorithm answers “no” is at least 0.982/3.

4.4 Testers for Weak Periodicity: Wrap-up

Corollary 23.

For kεn/4, there is a non-adaptive ε-tester for weak (p,k)-periodicity with complexity 𝒪(min(ε2klogk,ε1n/(k+p))).

Proof.

We first show that there is a tester with complexity 𝒪(ε2klogk). If k>ε2n/320 then the claimed number of queries exceeds n, and we simply query the whole string. Otherwise, at least one of p>2560k/ε or p40k/ε holds, and hence we can use one of Lemma 15 and Lemma 17 with c=40. The final claim follows by combining with Lemma 21.

Corollary 24.

For kεn/4, there is a non-adaptive ε-tester for weak (g,k)-periodicity with complexity 𝒪(min(log2g/ε2+klog(gk)/ε2+g(k+logg)/ε,nloggεk)).

Proof.

We first show that there is a tester with complexity 𝒪(log2g/ε2+klog(gk)/ε2+g(k+logg)/ε). If k>ε2n/(84096+(lng)/k), then klog(gk)/ε2=Ω(n), and we can simply query the whole string in the claimed complexity. Otherwise, we use Lemma 19. The final claim follows by combining this result with Lemma 22.

5 Lower Bounds for Weak Periodicity Testing

The proof of the following proposition is deferred to Appendix B.

Proposition 25.

Let M[0..n), m=|M|, and g[2..n2]. For p[2..g], define the set Mp:={(i,j)M2i<j and ij(modp)}. If we choose p(g/2..g]Primes uniformly at random, then for all x>0, Pr(|Mp|>x)(m2log2nlng)/(gx).

Proposition 26.

Let T[0..n) be a string with at most k wildcards, M[0..n) a subset of its positions, and f:MΣ satisfy T[i]=f(i) for iM. If M contains neither an implicit nor an explicit p-witness, then the symbols T[i], iM, can be chosen so that T is weakly (p,k)-periodic.

Proof.

Consider an equivalence class Tj of T. If Tj contains only undefined symbols, we fill it with an arbitrary symbol of Σ and exclude it from further consideration. Otherwise, we divide Tj from left to right into maximal factors such that, for each such factor, all its symbols are either equal to a fixed symbol of Σ or undecided. For two neighboring factors F1=Tj[x..y) and F2=Tj[y..z), we cannot have both the symbols adjacent to the boundary defined (i.e., we cannot have both (y1)p+(jmodp),yp+(jmodp)M). Otherwise, the maximality property implies that F1[|F1|1] and F2[1] must be different, and hence we have an explicit p-witness in M. Let kj be the number of factors in Tj. We have j(kj1)k, or otherwise we can form an implicit p-witness in M by taking pairs of positions of defined symbols in neighboring factors. Now, we explain how to complete T. We place a wildcard in one of the boundary positions of each pair of neighboring factors, which requires at most k wildcards. Then, we fill each factor with the single symbol from Σ occurring in it. The resulting string is weakly (p,k)-periodic and contains at most k wildcards.

Next, we define and analyze an auxiliary distribution on strings in Σn. We start by drawing a potential period p[g/2..g]Primes uniformly at random. The classes Tj, for j[0..8εp), are chosen to be unary: for all i, Tj[i]=j+2. The remaining classes are constructed as follows. For each j(8εp..p), we consider a partition Tj=Tj0Tj1Tj2Tj4, where each Tji is of length |Tj|/4 or |Tj|/4, Tj0 contains only zeros, and Tj1 contains only ones. Tj2 is constructed using a two-state Markov chain as follows: Tj[2]=1 and, for every position i[1..|Tj2|), we assign Tj2[i]=1Tj2[i1] with probability r=100(p+k)/n, and Tj2[i]=Tj2[i1] otherwise. Tj3 is defined in the same way as Tj2, but starting with a 0.

Lemma 27.

A random string T of length n drawn according to satisfies each of the following for integers k and g with k<g/4<gn/(64lnn) and a constant ε<1/64:

  • T is ε-far from a weakly (p,k)-periodic string for all pp with pg with probability 1 and ε-far from a weakly (p,k)-periodic string with probability at least 0.8;

  • T has less than 2000(p+k) explicit p-witnesses with probability at least 0.99.

Proof.

The lemma follows directly from Claims 28, 29, and 30 shown below.

Claim 28.

T is ε-far from a weakly (p,k)-periodic string for any pp with pg.

Proof.

For every j[0..8εp) we have Tj[i]=T[ip+j]T[ip+jp]=Tjpmodp[i], because jpmodpj, meaning that T[ip+jp] is in a different class modulo p (either in a different class among the first 8εp classes or in a binary class). This implies that in order to obtain a weak (p,k)-periodic string from T one needs to change at least half of the symbols of the classes Tj, j[0..8εp), or 8εp(n/p/21)εn symbols in total. Hence T is ε-far from every period in ([1..2p]{p})[1..g]{p}.

Claim 29.

With probability at least 0.99, T has less than 2000(p+k) explicit p-witnesses.

Proof.

Let Nj be the number of pairs (a,a+1) such that a|Tj0Tj1| and Tj[a]Tj[a+1]. Let N=j(2+Nj)=2p+jNj, which is an upper bound on the total number of explicit p-witnesses in T. We have Nj𝖡𝗂𝗇(|Tj|/2,r)+Xj, where Xj[5..5] takes care of the ceilings and floors, and the transition between Tj2 and Tj3. Hence, we have jNj𝖡𝗂𝗇((np)/2,r)+Xp, where X[5..5]. Then, by Fact 33, 𝖡𝗂𝗇((np)/2,r)5rn1000(p+k) with probability 0.99. As we have 2p+1000(p+k)+5p<2000(p+k), the claim follows.

Claim 30.

With probability at least 0.8, T is ε-far from a weakly (p,k)-periodic string.

Proof.

To make T weakly (p,k)-periodic, we must ensure that each equivalence class Tj can be partitioned into kj factors of identical symbols separated by kj1 wildcards, where j(kj1)k. We show that we cannot achieve this by changing at most εn symbols with good probability. Since k<g/4 and g/2p, there are at least p/4 classes Tj such that kj=0. Among those, there are at least p/8 classes where we can change at most ε8n/p symbols. We consider one such class Tj with j>8εp, which is possible since ε<1/64. It contains at least |Tj0| zeros and at least |Tj1| ones. Hence, we must change at least n/4p>ε8n/p symbols to obtain a unary string.

Theorem 31.

Every non-adaptive one-sided ε-tester for weak (g,k)-periodicity has complexity Ω(min(gk/(lognlogg),max(n/logg,n/k))), assuming ε<1/64 and k<g/4<gn/(64lnn).

Proof.

We use Yao’s principle adapted for one-sided algorithms: to prove that a one-sided tester requires at least m queries, we show a distribution 𝒟 on k-wildcard strings for which every deterministic tester that performs m queries either answers “no” on a weakly (g,k)-periodic string with non-zero probability, or answers “yes” on an ε-far string with probability greater than 1/3 (when the string is drawn via 𝒟). The distribution 𝒟 is defined as follows: with probability 3/4, a string is drawn according to , and with probability 1/4 we draw a weakly (p,k)-periodic string uniformly at random.

By Proposition 26, if the set of queried positions does not form either explicit or implicit p-witnesses for some pg, the input can be completed as a weakly (p,k)-periodic string. Thus, assuming that the tester does not return “no” on weakly (p,k)-periodic strings with positive probability, the tester must return “yes” if the set of queried symbols contains neither explicit nor implicit p-witnesses for some p[1..g].

Henceforth, we assume that the input string drawn according to 𝒟 is ε-far from a weakly (g,k)-periodic string, which by Lemma 27 happens with probability at least 0.6. It suffices to upper bound the probability that a deterministic algorithm hits either an implicit or an explicit p-witness for all p[1..g] on such string. By Lemma 27, this probability is upper-bounded by the probability that an algorithm hits an implicit or an explicit p-witness.

Fix an arbitrary set M[0..n) of size m. If m<0.01gk/(log2nlng), then by Lemma 27 the probability that |Mp|k and hence the probability that the algorithm hits an implicit p-witness is at most (0.01)2 (regardless of the actual string).

Now note that the space of explicit p-witnesses can be defined as [n], since for each explicit p-witness (a,b) we have b=a+p. Consequently, if m<n/(20000(p+k)), then by Lemma 27, the expected number of explicit p-witnesses hit by a deterministic algorithm is less than 1/10, which implies that a deterministic algorithm misses an explicit p-witness with probability at least 0.9 by Markov’s inequality (Fact 32).

Finally, let Mp={(i,j)M2i<j and ij(modp)}. By Proposition 25, we have Pr(|Mp|>1000m2lng/g)<0.001. If mgn/(41014(p+k)lng), then Pr(|Mp|>n/(2104(p+k)))<0.001. Furthermore, by Lemma 27, the expected number of explicit p-witnesses hit by M is less than |Mp|2000(p+k)/n<(n/(2104(p+k)))2000(p+k)/n<1/10 conditional on |Mp|<n/(2104(p+k))). Hence, the probability that that a deterministic algorithm misses an explicit p-witness conditional on |Mp|<n/(2104(p+k))) is at least 0.9 by Markov’s inequality (Fact 32). By the union bound, the probability that an algorithm misses all explicit witnesses in this case is at least 0.8.

Thus, if any of these conditions of m is satisfied, the algorithm fails with probability at least 0.60.8>1/3, a contradiction. The statement follows.

References

  • [1] Christine Awofeso, Ben Bals, Oded Lachish, and Solon P. Pissis. Testing quasiperiodicity. In Proceedings of the International Symposium on String Processing and Information Retrieval (SPIRE 2026), pages 1–9, 2026. doi:10.1007/978-3-032-05228-5_1.
  • [2] Jean Berstel and Luc Boasson. Partial words and a theorem of Fine and Wilf. Theoretical Computer Science, 218(1):135–141, 1999. doi:10.1016/S0304-3975(98)00255-2.
  • [3] F. Blanchet-Sadri. Periodicity on partial words. Computers & Mathematics with Applications, 47(1):71–82, 2004. doi:10.1016/S0898-1221(04)90006-5.
  • [4] F. Blanchet-Sadri, Deepak Bal, and Gautam Sisodia. Graph connectivity, partial words, and a theorem of Fine and Wilf. Information and Computation, 206(5):676–693, 2008. Special Issue: The 17th International Conference on Concurrency Theory (CONCUR 2006). doi:10.1016/j.ic.2007.11.007.
  • [5] F. Blanchet-Sadri, Travis Mandel, and Gautam Sisodia. Periods in partial words: An algorithm. Journal of Discrete Algorithms, 16:113–128, 2012. doi:10.1016/j.jda.2012.04.001.
  • [6] Francine Blanchet-Sadri, Taktin Oey, and Timothy D. Rankin. Fine and Wilf’s theorem for partial words with arbitrarily many weak periods. Int. J. Found. Comput. Sci., 21(5):705–722, 2010. doi:10.1142/S0129054110007519.
  • [7] Francine Blanchet-Sadri and Nathan D. Wetzler. Partial words and the critical factorization theorem revisited. Theor. Comput. Sci., 385(1-3):179–192, 2007. doi:10.1016/J.TCS.2007.06.012.
  • [8] Timothy M. Chan, Shay Golan, Tomasz Kociumaka, Tsvi Kopelowitz, and Ely Porat. Approximating text-to-pattern Hamming distances. In Proceedings of the 52nd Annual ACM SIGACT Symposium on Theory of Computing (STOC 2020), pages 643–656. ACM, 2020. doi:10.1145/3357713.3384266.
  • [9] Funda Ergun, S. Muthukrishnan, and Cenk Sahinalp. Periodicity testing with sublinear samples and space. ACM Trans. Algorithms, 6(2), April 2010. doi:10.1145/1721837.1721859.
  • [10] Funda Ergün, S. Muthukrishnan, and Süleyman Cenk Sahinalp. Sublinear methods for detecting periodic trends in data streams. In LATIN 2004, volume 2976 of LNCS, pages 16–28, 2004. doi:10.1007/978-3-540-24698-5_6.
  • [11] Nathan J. Fine and Herbert S. Wilf. Uniqueness theorems for periodic functions. Proceedings of the American Mathematical Society, 16(1):109–114, 1965. doi:10.2307/2034009.
  • [12] Svante Janson, Tomasz Łuczak, and Andrzej Ruciński. Random Graphs, chapter Exponentially Small Probabilities, pages 25–51. Wiley-Interscience, 2000. doi:10.1002/9781118032718.ch2.
  • [13] Ce Jin and Tomasz Kociumaka. Near-optimal property testers for pattern matching. In 66th IEEE Annual Symposium on Foundations of Computer Science (FOCS 2025), pages 1639–1647. IEEE Computer Society, 2025. doi:10.1109/FOCS63196.2025.00086.
  • [14] Tomasz Kociumaka, Jakub Radoszewski, Wojciech Rytter, and Tomasz Waleń. A periodicity lemma for partial words. Inf. Comput., 283(C), February 2022. doi:10.1016/j.ic.2020.104677.
  • [15] Oded Lachish and Ilan Newman. Testing periodicity. Algorithmica, 60(2):401–420, 2011. doi:10.1007/s00453-009-9351-y.
  • [16] Michael Mitzenmacher and Eli Upfal. Probability and Computing: Randomized Algorithms and Probabilistic Analysis. Cambridge University Press, 2nd edition, 2017.
  • [17] J. Barkley Rosser and Lowell Schoenfeld. Approximate formulas for some functions of prime numbers. Illinois Journal of Mathematics, 6(1), March 1962. doi:10.1215/ijm/1255631807.
  • [18] A. M. Shur and Yu. V. Gamzova. Partial words and the interaction property of periods. Izvestiya: Mathematics, 68(2):405–428, 2004. doi:10.1070/IM2004v068n02ABEH000480.
  • [19] Arseny M. Shur and Yulia V. Konovalova. On the periods of partial words. In Mathematical Foundations of Computer Science 2001, pages 657–665, 2001. doi:10.1007/3-540-44683-4_57.
  • [20] W.F. Smyth and Shu Wang. A new approach to the periodicity lemma on strings with holes. Theoretical Computer Science, 410(43):4295–4302, 2009. doi:10.1016/j.tcs.2009.07.010.

Appendix A Probability Inequalities Used in This Work

Fact 32 (Markov’s inequality).

Let X be a nonnegative random variable and t>0.

Pr[Xt]𝔼[X]t.
Fact 33 (Multiplicative Chernoff bounds, see e.g. [16]).

Let X1,,Xn be independent random variables taking values in {0,1} and let X=i=1nXi, μ=𝔼[X]. Then, for any 0<δ1,

Pr[|Xμ|δμ]2exp(δ2μ3), and Pr[X(1δ)μ]exp(δ2μ2),

and for any δ>0,

Pr[X(1+δ)μ]exp(δ2μ2+δ).
Fact 34 (The extended Janson inequality [12, Theorem 2.14 and Remark 2.15]).

Let Ω be a finite universal set and let R be a random subset of Ω given by Pr[rR]=pr, these events are mutually independent over rΩ.

Let {Ai}iI be subsets of Ω, where I a finite index set, and Bi be the event AiR. Let Xi be the indicator random variable for Bi and X=iXi be the number of AiR.

For i,jI we write ij if ij and AiAj. Define Δ=12ijPr[BiBj] and μ=𝔼[X], then Pr[iIBi¯]eμ2/(μ+2Δ).222The original claim in [12] states 2Δ¯ instead of μ+2Δ; for t=μ, this can be strengthened to Δ¯ by observing that φ(t/μ)=φ(1)=1.

Appendix B Omitted Proofs

Lemma 10. [Restated, see original statement.]

For g[2..n2] and ε(lngg)1/6, Algorithm 2 is a one-sided ε-property tester for strong (g,k)-periodicity with complexity 𝒪(ε1glogg).

If kεn/32, for g[2..n2] and ε(lngg)1/3, Algorithm 2 is a one-sided ε-property tester for strong (g,k)-periodicity with complexity 𝒪(ε1/2glogg).

Proof.

Assume that the given string is strongly (p,k)-periodic with p[1..g]. Let h=g/p, then ph(g/2..g]. By the definition of witnesses, every ph-witness is also a p-witness. By Observation 7, the tester does not find a ph-witness and returns “yes”. We have shown that the tester accepts all strings that have a strong (p,k)-period for some p[1..g].

Now, assume T is ε-far from being strongly (g,k)-periodic. If the algorithm answers “yes”, then at least one of the following holds:

  • the algorithm samples |I|2rn positions (henceforth called event );

  • I does not contain a p-witness for some p(g/2..g] (henceforth called event 𝒢).

We will show that Pr[𝒢]<1/9 and Pr[]<1/9. Then, by the union bound, the probability that at least one of the events occurs (and hence the probability to answer “yes”) is at most 2/9<1/3. The probability of is at most exp(rn/3)exp(1024/3)<0.01 via a Chernoff bound (Fact 33 invoked with δ=1). We only query the input if |I|2rn and hence the complexity is as claimed.

For estimating the probability of 𝒢, let 𝒢p be the event that the algorithm does not find a p-witness. Then, by the union bound, Pr[𝒢]p(g/2..g]Pr[𝒢p]. Hence, we can conclude the proof by showing that Pr[𝒢p]1/(9g), which implies Pr[𝒢]1/9.

Let Wp be the set of p-witnesses. Lemma 8 implies that |Wp|10242glng/(pr2). (One gets this bound by observing that, in both cases for k, the product of r2 and the corresponding bound from Lemma 8 equals 10242glng/p). For a fixed p-witness, the probability of sampling both of its positions is r2. Hence, the expected number of sampled p-witnesses is at least μ:=r2|Wp|10242glng/p10242lng.

By the extended Janson inequality (Fact 34), the probability of not sampling any p-witness is at most exp(μ2/(μ+2Δ)). Here, Δ is a correlation term that accounts for the fact that pairs are not sampled independently. To explain Δ, we introduce the following notation. For two potential witnesses w1:=(a,b)[0..n)2 and w2:=(c,d)[0..n)2, we write w1w2 if and only if |{a,b,c,d}|=3, i.e., if they share exactly one position. Note that the probability of sampling both w1 and w2 is r3. Also, the three distinct positions of w1 and w2 are in the same equivalence class. Now we can define Δ and provide an upper bound using

2Δ:=w1,w2Wpw1w2r3w1,w2[0..n)2w1w2r3p(n/p3)r3r3n3p24r3n3g2.

For our range of ε, we have r102416g4/3ln2/3g/n2, which readily implies 2Δ1024364lng. Finally, if μ2Δ then μ2/(μ+2Δ)μ/21210242lng. Otherwise, μ2/(μ+2Δ)μ2/(4Δ)10244lng/(10243128)8lng. Hence, exp(μ2/(μ+2Δ))exp(8lng)=1/g81/(9g) for g2, which concludes the proof.

Proposition 35.

For every integer g2, we have |[g/2..g]Primes|>g/(10lng).

Proof.

The number of primes in [g/2..g] is at least 1g/(10lng) for 2g16. For g>16, it is at least g/lng(g/2)(ln(g/2)3/2)g/(10lng), see Theorem 2 and Corollary 1 of [17].

Proposition 25. [Restated, see original statement.]

Let M[0..n), m=|M|, and g[2..n2]. For p[2..g], define the set Mp:={(i,j)M2i<j and ij(modp)}. If we choose p(g/2..g]Primes uniformly at random, then for all x>0, Pr(|Mp|>x)(m2log2nlng)/(gx).

Proof.

By Proposition 35, [2..g] contains at least g/(10lng) primes. For every (i,j)Mp, we know that p divides d:=ji. By the prime factorization theorem, d has at most log2dlog2n distinct prime factors, and thus each pair (i,j)M2 participates in the set Mp for at most log2n different choices of p. Hence, p[1..g]Primes|Mp|m2log2n. Therefore, 𝔼[|Mp|]10(m2log2nlng)/g. The claim follows by Markov’s inequality (Fact 32).