**2. Preliminaries**

We use the standard form of the quantum query model. Let *f* : *D* → {0, <sup>1</sup>}, *D* ⊆ {0, 1}*<sup>N</sup>* be an *N* variable function. An input for the function is *x* ∈ *D*. We are given an oracle access to the input *x*, i.e., it is realized by a specific unitary transformation usually defined as |*i* |*z* |*w* →|*i* |*z* + *xi* (mod 2) |*w* , where the |*i* register indicates the index of the variable we are querying, |*z* is the output register, and |*w* is some auxiliary workspace. Note that we use Dirac notation vectors. An algorithm in the query model consists of alternating applications of arbitrary unitaries independent of the input and the query unitary and a measurement in the end.

In the case of non-binary input, we present the input variables in binary form. Using alternating unitaries independent of the input, we can store bits in auxiliary work-space |*w* and use the obtained variable in an algorithm. In the case of computing a complex function *f* and additionally non-binary input, we can consider a block of alternating unitaries independent of the input and the query unitary that stores required variables in the auxiliary work-space |*w* . Then, we compute the Boolean value of the function *f* on arguments and store them in the auxiliary work-space |*w* . After that, we can use the value of the function *f* in our algorithms.

The smallest number of queries for an algorithm that outputs *f*(*x*) with a probability that is at least 2 3 on all *x* is called the quantum query complexity of the function *f* and is denoted by *Q*(*f*). We refer the readers to [1–3] for more details on quantum computing.

In the quantum algorithms in this article, we discuss quantum query complexity. We use modifications of Grover's search algorithm [27,28] as quantum subroutines. For these subroutines, time complexity (number of gates in a circuit) is more than query complexity for an additional log factor. Note that the query can be implemented using the CNOT gate.

#### **3. The Quantum Algorithm for Comparing Two Strings**

Firstly, we discuss a quantum subroutine that compares two strings of length *k*. Assume that this subroutine is COMPARE\_STRINGS(*<sup>s</sup>*, *t*, *k*), and it compares *s* and *t* in the lexicographical order. It returns:


As a base for our algorithm, we use the algorithm of finding the minimal argumen<sup>t</sup> with 1-result of a Boolean-value function. Formally, we have:

**Lemma 1** ([24,25], Theorem 10; [23], Section 2.2; [26], Proposition 4)**.** *Suppose we have a function f* : {1, ... , *N*}→{0, 1} *for some integer N. There is a quantum algorithm for finding j*0 = min{*j* ∈ {1, ... , *N*} : *f*(*j*) = <sup>1</sup>}*. The algorithm finds j*0 *with the expected query complexity O*( &*j*0) *and error probability that is, at most,* 1 2*.*

Let us choose the function *f*(*j*)=(*sj* = *tj*). Thus, we search for *j*0 that is the index of the first unequal symbol of the strings. Then, we can claim that *s* precedes *t* in the lexicographical order if the symbol *sj*0 precedes the symbol *tj*0 . The claim is right by the definition of the lexicographical order. If there are no unequal symbols, then the strings are equal.

If we discuss the implementation of the *f* , then we can say that for computing the value *f*(*j*), we store the binary representation of *sj* and *tj* in the auxiliary work-space, for example, |*ψs* and |*ψt* . Then, compute the value of *f*(*j*) and store it in a qubit |*φ* . After that, we can use this value in the algorithm. The last step is clearing |*φ* using values of |*ψs* and |*ψt* and the CNOT gate; then, clearing |*ψs* and |*ψt* repeatedly using the same queries (that use CNOT gates). All these manipulations take a constant number of queries because of the constant size of the input alphabet.

We use THE\_FIRST\_ONE\_SEARCH(*f* , *k*) as a subroutine from Lemma 1, where *f*(*j*) = (*sj* = *tj*). Assume that this subroutine returns *k* + 1 if it does not find any solution or the found argumen<sup>t</sup> *j* is such that *f*(*j* ) = 0.

We use the standard technique of boosting success probability. Thus, we repeat the subroutine log2(*<sup>δ</sup>*−<sup>1</sup>) times and return the minimal answer.

Suppose the subroutine has an error. There are two cases. The first one is finding the index of unequal symbols that is not the minimal one. In the second case, the algorithm does not find unequal symbols. Then, we assume that it returns *k* + 1. Thus, in a case of an error, the subroutine returns a value that is bigger than the correct answer.

Therefore, if at least one subroutine invocation has no error, then the whole algorithm succeeds. All error events are independent. The error probability of the whole algorithm is the probability of error for all invocations of the subroutine, that is *O* 1 2log2(*<sup>δ</sup>*−<sup>1</sup>) = *<sup>O</sup>*(*δ*). Let us present the Algorithm 1.

**Algorithm 1** COMPARE\_STRINGS(*<sup>s</sup>*, *t*, *k*). The Quantum Algorithm for Comparing Two Strings.


The next property follows from the previous discussion.

**Lemma 2.** *Algorithm 1 compares two strings of length k in the lexicographical order with query complexity O*(√*k* log *<sup>δ</sup>*−<sup>1</sup>) *and error probability O*(*δ*) *for some integer k and* 0 < *δ* < 1*.*

The algorithm finds the minimal index of unequal symbols *j*0. We can say that *j*0 − 1 is the length of the longest common prefix for these strings.

We can show that the lower bound for the problem is <sup>Ω</sup>(√*k*).

**Lemma 3.** *Any quantum algorithm for Comparing Two Strings problem has* Ω(√*k*) *query complexity.*

**Proof.** Let us show that the problem is at least as hard as the unstructured search problem. Let *<sup>s</sup>k*/2 = 1 and *sj* = 0 for all *j* ∈ {1, . . . , *k*/2 − 1, *k*/2 + 1, . . . *k*}. The string *t* is such that there is only one 1 in position z. In other words, there is *z* ∈ {1, ... , *k*} such that *tz* = 1 and *tj* = 0 for all *j* ∈ {1, . . . , *z* − 1, *z* + 1, . . . *k*}.

If *z* < *k*/2, then *t* > *s*. If *z* = *k*/2, then *t* = *s*. If *z* > *k*/2, then *t* < *s*. Therefore, the problem is at least as hard as the search for 1 among the first *k*/2 variables in the string *t*.

It is known [14] that the quantum query complexity of the unstructured search among *k*/2 variables is <sup>Ω</sup>(√*k*).

At the same time, the classical complexity of the problem is <sup>Θ</sup>(*k*).

**Lemma 4.** *Randomized query complexity for Comparing Two Strings problem is* <sup>Θ</sup>(*k*)*.*

**Proof.** Due to the proof of Lemma 3, the problem is at least as hard as the search for 1 among the first *k*/2 variables in the string *t*.

It is known [14] that the randomized query complexity of the unstructured search among *k*/2 variables is <sup>Ω</sup>(*k*).

At the same time, we can check all symbols sequentially to search the first unequal symbol. This algorithm has *O*(*k*) query complexity.

Additionally, we can compute the complexity of any algorithm based on the two strings comparison procedure.

**Lemma 5.** *Suppose we have some integer n, integer A* = *<sup>A</sup>*(*n*) *and ε such that* lim*n*→ ∞ *ε*/*A* = 0*. Then, if a quantum algorithm does <sup>A</sup>*(*n*) *comparisons of strings of length k and has <sup>O</sup>*(*ε*) *error probability, then it does at most O*(*A* √*k* log(*A*/*ε*)) *queries.*

**Proof.** As a strings comparison procedure, we use COMPARE\_STRINGS subroutine for *δ* = *<sup>ε</sup>*/*A*. Because of Lemma 2, the complexity of the subroutine is *O*( √*k* log(*A*/*ε*)), and the error probability is *<sup>O</sup>*(*ε*/*A*). Because of *A* comparison operations, the total complexity of the algorithm is *O*(*A* √*k* log(*A*/*ε*)).

Let us discuss the error probability. Events of error in the algorithm are independent. Thus, all events should be correct. The error probability for one event is 1 − (1 − *<sup>ε</sup>*/*A*). Hence, the error probability for all *A* events is at least 1 − (1 − *ε*/*A*) *A* = 1 − (1 − *ε*/*A*) *A*. Notethat

$$\lim\_{n \to \infty} \frac{1 - \left(1 - \frac{\varepsilon}{A}\right)^A}{\varepsilon} = \lim\_{n \to \infty} \frac{1 - \left(1 - \frac{\varepsilon}{A}\right)^{\frac{A}{\varepsilon} \cdot \varepsilon}}{\varepsilon} \le 1;$$

Hence, the total error probability is at most *<sup>O</sup>*(*ε*).

#### **4. Strings Sorting Problem**

Let us consider the following problem.

Problem. For some positive integers *n* and *k*, we have the sequence of strings *s* = (*s*1, ... ,*s<sup>n</sup>*). Each *si* = (*si* 1, ... ,*si k*) ∈ Σ*<sup>k</sup>* for some finite size alphabet Σ. We search an order *ORDER* = (*<sup>i</sup>*1, ... , *in*) such that for any *j* ∈ {1, ... , *n* − <sup>1</sup>}, we have *s ij* ≤ *s ij*+<sup>1</sup> in the lexicographical order.

We use one of the existing sorting algorithms (for example, Heapsort algorithm [34,35] or the Merge sort algorithm [34]) as a base and the quantum algorithm for string comparison from Section 3. In fact, our comparison function can have errors. That is why we use the result for "noisy computation" from [36]. The result is presented in the following lemma.

**Lemma 6** ([36], Theorem 3.5)**.** *Suppose we have a comparison procedure that works with error probability ε. Then there is a sorting algorithm with query complexity <sup>O</sup>*(*n* log(*n*/*ε*)) *and error probability at most ε.*

The complexity of the algorithm is presented in the following theorem.

**Theorem 1.** *The algorithm sorts s* = (*s*1, ... ,*s<sup>n</sup>*) *with query complexity <sup>O</sup>*(*n*(log *n*) · √*k*) = *<sup>O</sup>*˜(*n* √*k*) *and constant error probability.*

**Proof.** The correctness of the algorithm follows from the description. Let *ε* = 0.1. Then, we apply the result from Lemma 6 and use the quantum comparison procedure that has *ε* error probability and *O*( √*k* log *ε*<sup>−</sup><sup>1</sup>) = *O*( √*k*) query complexity. Therefore, the query complexity of the algorithm is *<sup>O</sup>*(*n*(log(*n*/*ε*)) · √*k*) = *<sup>O</sup>*(*n*(log *n*) · √*k*) = *<sup>O</sup>*˜(*n* √*k*), and the error probability is *ε*.

We can show the lower bound for the problem.

**Theorem 2.** *Any quantum algorithm for the Sorting problem has* Ω( √*nk*) *query complexity.*

**Proof.** Let us show that the problem is at least as hard as the unstructured search problem. Assume that strings *s*1,...,*s<sup>n</sup>* are such that


In that case, the answer is *ORDER* = (*<sup>i</sup>*1, ... , *in*−1, *<sup>u</sup>*), where (*<sup>i</sup>*1, ... , *in*−<sup>1</sup>) is a permutation of integers from {1, ... , *u* − 1, *u* + 1, ... , *<sup>n</sup>*}. The searching for the required index *u* is at least as hard as the search for the 1-value variable *suv*.

It is known [14] that the quantum complexity of the unstructured search among *nk* variables is <sup>Ω</sup>(√*nk*).

The lower bound for classical complexity can be proven by the same way as in Theorem 2.

**Theorem 3.** *The randomized query complexity of the Sorting problem is* <sup>Θ</sup>(*nk*)*.*

**Proof.** Due to the proof of Theorem 2, the problem is at least as hard as the search for 1 among *nk* variables in the strings *<sup>s</sup>*1,...,*sn*.

It is known [14] that the randomized query complexity of the unstructured search among *nk* variables is <sup>Ω</sup>(*nk*).

The Radix sort [34] algorithm reaches this bound and has *O*(*nk*) complexity in a case of a finite alphabet.

#### **5. The Most Frequent String Search Problem**

Let us formally present the problem.

Problem. For some positive integers *n* and *k*, we have a sequence of strings *s* = (*s*1, ... ,*s<sup>n</sup>*). Each *si* = (*si*1, ... ,*<sup>s</sup>ik*) ∈ Σ*<sup>k</sup>* for some finite size alphabet Σ. Let #(*t*) = |{*i* ∈ {1, ... , *n*} : *si* = *t*}| be the number of occurrences of a string *t*. We search for *i* = *argmaxi*∈{1,...*n*}#(*s<sup>i</sup>*). If several strings satisfy the condition, then the answer is the index of the string with minimal index in the set *s*. Formally, *i* is such that:

$$i = \min\{j : \mathfrak{\*}(s^j) = \max\_{z \in \{1, \ldots, n\}} \#(s^z)\}$$

Firstly, we present an idea of the algorithm.

The algorithm contains two steps. The first step is sorting the sequence of strings and obtaining *ORDER* = (*<sup>i</sup>*1, ... , *in*) such that for any *j* ∈ {1, ... , *n* − <sup>1</sup>}, we have *sij* ≤ *sij*+<sup>1</sup> in the lexicographical order. In that case, equal strings are situated sequentially. On the second step, we find each segmen<sup>t</sup> [*i*-, *ir*] of indexes for equal strings, i.e., *sj* = *si*- for *j* ∈ {*<sup>i</sup>*-, ... , *ir*} and *si*-−1 = *si*- or - = 1, and *sir*+<sup>1</sup> = *sir* or *r* = *n*. We check segments for different strings one by one. We store the longest segment's length as *cmax* and the minimal index of the string that corresponds to this segmen<sup>t</sup> in *jmax*. As in the sorting algorithm, in the second step of the algorithm, we apply the COMPARE\_STRINGS subroutine for checking the equality of strings. Assume that we have the SORT\_STRINGS(*s*) subroutine that implements the algorithm from Section 4.

Let us present the algorithm formally in Algorithm 2.

Let us discuss the complexity of the algorithm.

**Theorem 4.** *Algorithm 2 finds the most frequent string from s* = (*s*1, ... ,*s<sup>n</sup>*) *with query complexity <sup>O</sup>*(*n*(log *n*) · √*k*) = *<sup>O</sup>*˜(*n*√*k*) *and constant error probability.*

**Proof.** The correctness of the algorithm follows from the description. Let us discuss the query complexity. Because of Theorem 1, the sorting algorithm's complexity is *<sup>O</sup>*(*n*(log *<sup>n</sup>*)√*k*), and the error probability is constant. The second step does *<sup>O</sup>*(*n*) comparison operations. Let *ε* = 0.1. Thus, because of Lemma 5, the second step of the algorithm algorithm does *<sup>O</sup>*(*n*(log *n*)√*k*) queries, and the error probability is constant. The total complexity is *<sup>O</sup>*(*n*(log *n*)√*<sup>k</sup>* + *n*(log *n*)√*k*) = *<sup>O</sup>*(*n*(log *<sup>n</sup>*)√*k*).

Error events of two steps are independent. Therefore, the error probability of the whole algorithm is also constant. We can achieve any required constant error probability by repetition. The technique is standard in both one-side and two-side errors. It can be seen, for example, in [16].

**Algorithm 2** The Quantum Algorithm for the Most Frequent String Problem.

(*<sup>i</sup>*1,..., *in*) = *ORDER* ← SORT\_STRINGS(*s*) We sort *s* = (*s*1,...,*s<sup>n</sup>*). *cmax* ← 0, *jmax* ← −1 *c* ← 1, *j* ← *i*1 **for** *b* ∈ (1, . . . , *n*) **do if** *b* = *n* or (*b* = *n* and COMPARE\_STRINGS(*sib* ,*<sup>s</sup>ib*+<sup>1</sup> , *k*) = 0) **then** We find the end of a segmen<sup>t</sup> **if** *c* > *cmax* **then** If the current segmen<sup>t</sup> is longer than the current longest one *cmax* ← *c*, *jmax* ← *j* **end if** *c* ← 1 **if** *b* = *n* **then** *j* = *ib*+<sup>1</sup> **end if else** *c* ← *c* + 1 **if** *ib*+<sup>1</sup> < *j* **then** *j* is the minimal index of the current segmen<sup>t</sup> *j* ← *ib*+1. **end if end if end for return** *jmax*

**Theorem 5.** *Suppose we have a constant ε such that* 0 < *ε* < 3/4*. If the length of the strings k* ≥ log2 *n, then any quantum algorithm for the Most Frequent String Search problem has* Ω(√*nk* + *n*3/4−*<sup>ε</sup>*) *query complexity. If k* < log2 *n, then any quantum algorithm for the Most Frequent String Search problem has* Ω(√*nk*) *query complexity*

**Proof.** Let us show that the problem is at least as hard as the unstructured search problem. Assume that *n* = 2*t* and *k* > 1 for some integer *t*. Then, let *st*+1, ... ,*s*2*<sup>t</sup>* = <sup>0</sup>*k*, where 0*k* is a string of *k* zeros. Other strings can be *s*1, ... ,*s<sup>t</sup>* = 1*k* or there are *z* ∈ {1, ... , *t*} and *u* ∈ {1, . . . , *k*} such that *szu* = 0 and *szu* = 1 for all *u* ∈ {1, . . . , *u* − 1, *u* + 1, . . . , *k*}.

In the first case, the answer is 1*k*. In the second case, the answer is 0*k*. Therefore, solving the problem for this instance is equivalent to the search for 0 among the first *tk* = *nk*/2 variables.

According to [14], the quantum complexity of the unstructured search among *nk*/2 is <sup>Ω</sup>(√*nk*).

In the case of odd *n*, we assign *s<sup>n</sup>* = 1*<sup>k</sup>*/20*<sup>k</sup>*/2, and it is not used in the search. Then, we can consider only *n* − 1 strings. Thus, *n* − 1 is even.

Let us consider the case of *k* = 1. If *n* is odd, then *s<sup>n</sup>* = 2. Let *si* = 0 for *i* ≥ *t* + 1, and *t* = *<sup>n</sup>*/2. Let us consider two cases. The first one is *si* = 1 for all *i* ∈ {1, ... , *t*}. The second case is *si* = 1 for all *i* ∈ {1, ... , *<sup>t</sup>*}\{*<sup>i</sup>*1} and *si*1 = 0 for some *i*1 ∈ {1, ... , *t*}. In the first case, the answer is 1. In the second case, the answer is 0. Therefore, solving the problem for this instance is equivalent to the search for 0 among the first *t* = *n*/2 = *nk*/2 variables.

Let us show that the problem is at least as hard as the *d*-distinctness problem [47]. Let *d* be such that 14*d* = *ε*/2. Let *b* be the maximal integer that satisfies *n* ≥ *b* · (*d* − 1) + 1. Let *uj* be a binary representation of *j* for *j* ∈ {0, . . . , *b*}.

Assume that *s*1 = *u*1 for other strings. We have two cases:

	- **–** #(*uj*) = *d* − 1 for *j* ∈ {1, . . . , *b*};
	- **–** #(*u*<sup>0</sup>) = *n* − *b* · (*d* − <sup>1</sup>).
	- **–** #(*ujm* ) = *d* for some *jm* ∈ {2, . . . , *b*};
	- **–** #(*uj*) = *d* − 1 for *j* ∈ {1, . . . , *b*}\{*jm*};
	- **–** #(*u*<sup>0</sup>) = *n* − *b* · (*d* − 1) + 1.

In the first case, #(*uj*) = *d* − 1 for *j* ∈ {1, ... , *b*}, #(*u*<sup>0</sup>) ≤ *d* − 1 and *s*1 = *u*1. Therefore, the answer is 1. In the second case, #(*uj*) = *d* − 1 for *j* ∈ {1, ... , *b*}\{*jm*}, #(*u*<sup>0</sup>) ≤ *d* − 1 and #(*ujm* ) = *d*. Therefore, the answer is *im* = min{*i* : *si* = *ujm* }. Note that *im* = 1 because *jm* ≥ 2 and *s*1 = *u*1 = *ujm* .

Hence, solving the problem for this instance is equivalent to checking whether there is a string that occurs in the input at least *d* times. It is the *d*-distinctness problem from

[47]. It is known that the complexity of the problem is Ω 1 <sup>4</sup>*dd*<sup>2</sup>·log5/2 *R* · *<sup>R</sup>*3/4−1/(4*d*)for *R* = <sup>Θ</sup>(*dd*/2*n*). In our case, the complexity is <sup>Ω</sup>(*n*3/4−*<sup>ε</sup>*).

Secondly, let us discuss the classical complexity of the problem.

**Theorem 6.** *Any randomized algorithm for the Most Frequent String Search problem has* Θ(*nk*) *query complexity.*

**Proof.** The best-known classical algorithm uses the radix sort algorithm and does steps similar to the steps of the quantum algorithm.

The running time of this algorithm is *<sup>O</sup>*(*nk*). At the same time, we can show that it is also a lower bound.

As it was shown in the proof of Theorem 5, the problem is at least as hard as the unstructured search problem among *nk*/2 variables. It is known [14] that the randomized complexity of the unstructured search among *nk*/2 variables is <sup>Ω</sup>(*nk*).

#### **6. Intersection of Two Sequences of Strings Problem**

Let us consider the following problem.

Problem. For some positive integers *n*, *m* and *k*, we have the sequence of strings *s* = (*s*1, ... ,*s<sup>n</sup>*). Each *si* = (*si*1, ... ,*<sup>s</sup>ik*) ∈ Σ*<sup>k</sup>* for some finite size alphabet Σ. Then, we obtain *m* requests *t* = (*t*1 ... *<sup>t</sup><sup>m</sup>*), where *ti* = (*ti*1, ... , *tik*) ∈ Σ*k*. The answer for a request *ti* is 1 if there is *j* ∈ {1, . . . , *n*} such that *ti* = *sj*. We should answer 0 or 1 to each of *m* requests.

Let us present the algorithm that is based on the sorting algorithm from Section 4. We sort strings from *s*. Then, we answer each request using a binary search in the sorted sequence of strings [34] and COMPARE\_STRINGS quantum subroutine for strings comparison during the binary search.

Let us present Algorithm 3. Assume that the sorting algorithm from Section 4 is the subroutine SORT \_ STRINGS(*s*), and it returns the order *ORDER* = (*<sup>i</sup>*1, ... , *in*). The subroutine BINARY \_ SEARCH \_ FOR \_ STRINGS(*ti*,*s*, *ORDER*) is the binary search algorithm with the COMPARE \_ STRINGS subroutine as a comparator, and it searches for *ti* in the ordered sequence (*si*<sup>1</sup> , ... ,*sin* ). Suppose that the subroutine BINARY\_SEARCH\_FOR\_STRINGS returns 1 if it finds *t* and 0 otherwise.

**Algorithm 3** The Quantum Algorithm for Intersection of Two Sequences of Strings Problem using sorting algorithm.

*ORDER* ← SORT \_ STRINGS(*s*) We sort *s* = (*s*1,...,*s<sup>n</sup>*). **for** *i* ∈ {1, . . . , *m*} **do** *ans* ← BINARY \_ SEARCH \_ FOR \_ STRINGS(*ti*,*s*,*ORDER*) We search *ti* in the ordered sequence. **return** *ans* **end for**

The algorithms have the following query complexity.

**Theorem 7.** *Algorithm 3 solves Intersection of Two Sequences of Strings Problem with query complexity <sup>O</sup>*((*n* + *m*)√*<sup>k</sup>* · log *n* · log(*n* + *m*)) = *<sup>O</sup>*˜((*n* + *m*)√*k*) *and error probability O* 1 *n*+*m .*

**Proof.** The correctness of the algorithm follows from the description.

Because of Theorem 1, the sorting algorithm's complexity is *<sup>O</sup>*(*n* log *n* · √*k*) and constant error probability.

Let us consider the second part of the algorithm. It does *<sup>O</sup>*(*m* log *n*) comparison operations for all invocations of the binary search algorithm. Let *ε* = 0.1. Thus, because of Lemma 5, the second part of the algorithm does

$$O(m\sqrt{k}\log n \log(m\log n)) = O(m\sqrt{k}\log n(\log m + \log \log n))$$

queries, and the error probability is constant.

Thus, the total complexity is *<sup>O</sup>*((*n* + *m*(log *m* + log log *n*))√*<sup>k</sup>* log *<sup>n</sup>*). Error events of the two steps are independent. Therefore, the error probability of the whole algorithm is also constant. We can achieve any required constant error probability by repetition.

The lower bound for the classical case can be proven using a result stated in [48] (Lemma 7, Section 5.1).

**Theorem 8.** *The randomized query complexity of Intersection of Two Sequences of Strings Problem is* <sup>Θ</sup>((*n* + *<sup>m</sup>*)*k*)*.*

**Proof.** Assume that *n* > *m*. Let us consider *t*1 = <sup>0</sup>*k*, and *si* contains only 0 s and 1 s, i.e., *sij* ∈ {0, 1} for all *i* ∈ {1, . . . , *<sup>n</sup>*}, *j* ∈ {1, . . . , *k*}.

For checking *si* = *t*1, it is enough to check ¬ '*k j*=1 (*sij* = 1) because this implies *sij* = 0

for all *j* ∈ {1, ... , *k*}. In that case, checking for the existence of *t*1 among *si* is the same as checking the following condition:

$$-\bigwedge\_{i=1}^{n} \bigvee\_{j=1}^{k} (s\_j^i = 1)$$

This condition means that not all string *si* contains at least one 1.

The randomized complexity of computing ¬ ' *k j*=1 (*sij* = 1) is the same as the complexity of the unstructured search for 1 among *k* variables, which is <sup>Ω</sup>(*k*). According to [48] (Lemma7,Section5.1),thetotalcomplexityofthefunctionis<sup>Ω</sup>(*nk*).

 Assume that *m* > *n*. Let us consider *si* = 0*k* for all *i* ∈ {1, ... , *<sup>n</sup>*}. The checking existence *tj* among *s*1, ... ,*s<sup>n</sup>* is at least as hard as the search for 1 among *tj*1, ... , *tjk* that requires Ω(*k*) queries. It is true for all *j* ∈ {1, ... , *<sup>m</sup>*}. Therefore, the total randomized complexity is <sup>Ω</sup>(*mk*).

Hence, if we join both cases, the randomized complexity of solving the problem is <sup>Ω</sup>(max (*<sup>n</sup>*, *m*) · *k*) = <sup>Ω</sup>((*n* + *m*) · *k*).

This complexity *<sup>O</sup>*((*n* + *m*)*k*) can be reached if we use the radix sort algorithm and perform the same operations as in the quantum algorithm.

Note that we can use the quantum algorithm for element distinctness [49,50] for this problem. The algorithm solves the problem of finding two identical elements in the sequence. The query complexity of the algorithm is *<sup>O</sup>*(*D*2/3), where *D* is the number of elements in the sequence. The complexity is tight because of [51]. The algorithm can be the following. On *j*-th request, we can add the string *tj* to the sequence *s*1, ... ,*s<sup>n</sup>* and invoke the element distinctness algorithm that finds a collision of *tj* with other strings. Such approach requires <sup>Ω</sup>(*n*2/3 √*k*) queries for each request and <sup>Ω</sup>(*mn*2/3 √*k*) for processing all requests. Note that the online nature of requests does not allow us to access all *t* 1, ... , *t m*. Thus, each request should be processed separately.

In a case of *n m*, we can use the Grover search algorithm for searching *tj* among (*<sup>s</sup>*1,...,*sn*). The complexity is *<sup>O</sup>*˜(*m* √*nk*) in that case.

Because of the probabilistic behavior of the Oracle, we should use the approach similar to [52] that uses ideas of Amplitude Amplification [53].
