**1. Introduction**

*Quantum computing* [1–3] is one of the hot topics in computer science in the last few decades. There are many problems where quantum algorithms outperform the best known classical algorithms [4–12].

One of these problems are problems for strings. Researchers show the power of quantum algorithms for such problems in [13–22].

In this paper, we consider three problems:


Our algorithms use some quantum algorithms as a subroutine, and the remaining part is classical. We investigate the problems in terms of query complexity. The query model is one of the most popular in the case of quantum algorithms. Such algorithms can do a query to a black box that has access to the sequence of strings. As a running time of an algorithm, we mean a number of queries to the black box.

In the paper, we suggested a quantum comparison procedure for two strings. We show that its quantum complexity is <sup>Θ</sup>(√*k*), where *k* is the length of strings. The classical complexity is <sup>Θ</sup>(*k*). Thus, the quantum algorithm has a quadratic speed-up compared to classical algorithms. We propose a quantum algorithm that is based on "the first one search" (The minimal element satisfying a condition) problem algorithm from [23–26]. This algorithm is a modification of Grover's search algorithm [27,28]. Another important

**Citation:** Khadiev, K.; Ilikaev, A.; Vihrovs, J. Quantum Algorithms for Some Strings Problems Based on Quantum String Comparator. *Mathematics* **2022**, *10*, 377. https:// doi.org/10.3390/math10030377

Academic Editors: Fernando L. Pelayo, Mauro Mezzini and Jan Sładkowski

Received: 12 November 2021 Accepted: 22 January 2022 Published: 26 January 2022

**Publisher's Note:** MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

**Copyright:** © 2022 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https:// creativecommons.org/licenses/by/ 4.0/).

41

algorithm for the search is described in [29]. Using this idea, we obtain quantum algorithms for several problems.

The first problem is the String Sorting problem. Assume that we have *n* strings of length *k*. It is known [30] that no quantum algorithm can sort arbitrary comparable objects faster than *<sup>O</sup>*(*n* log *<sup>n</sup>*). At the same time, several researchers tried to improve the hidden constant [31,32]. Other researchers investigated the space bounded case [33]. We focus on sorting strings. In a classical case, we can use an algorithm that is better than arbitrary comparable objects sorting algorithms. It is radix sort that has *O*(*nk*) query complexity [34] for a finite size alphabet. It is also a lower bound for classical (randomized or deterministic) algorithms that is <sup>Ω</sup>(*nk*). Our quantum algorithm for the string sorting problem has query complexity *<sup>O</sup>*(*n*(log *n*) · √*k*) = *<sup>O</sup>*˜(*n* √*k*), where *O*˜ does not consider log factors. It is based on standard sorting algorithms [34] or Heapsort [34,35] and the quantum algorithm for comparing strings. Additionally, we use the idea of a noisy comparison procedure for sorting [36].

The second problem is the following. We have *n* strings of length *k*. We can assume that string symbols are letters from any constant size alphabet, for example, binary, Latin alphabet, or Unicode. The problem is finding the string that occurs in the sequence most often. The problem [37] is one of the most well-studied ones in the area of data streams [38–41]. Many applications in packet routing, telecommunication logging, and tracking keyword queries in search machines are critically based on such routines. The bestknown classical (randomized or deterministic) algorithms require Ω(*nk*) queries because an algorithm should at least test all symbols of all strings. The deterministic solution can use the radix sort algorithm [34] or the Trie (prefix tree) [42–45] that allow achieving the required complexity.

We propose a quantum algorithm that is based on the sorting algorithm from the first problem. Our algorithm for the most frequent string search problem has query complexity *<sup>O</sup>*(*n*(log *n*) · √*k*) = *<sup>O</sup>*˜(*n* √*k*). If log2 *n* = *o*( √*k*), then our algorithm is better than classical counterparts. Note that this setup makes sense in practical cases.

The third problem is the Intersection of Two String Sequences problem. Assume that we have two sequences of strings of length *k*. The size of the first set is *n*, and the size of the second one is *m*. The first sequence is given, and the second one is given in an online fashion, one by one. After each requested string from the second sequence, we want to check whether this string belongs to the first sequence. We propose a quantum algorithm for the problem with quantum query complexity *<sup>O</sup>*((*n* + *m*(log *m* + log log *n*)) · log *n* · √*k*) = *<sup>O</sup>*˜((*n* + *m*) √*k*). The algorithm uses a quantum algorithm for sorting strings. At the same time, the best-known classical (randomized or deterministic) algorithm requires <sup>Ω</sup>((*n* + *m*)*k*) queries, and this bound is achieved using the radix sort algorithm or the Trie data structure.

The paper is an extended version of a conference paper [46].

The structure of the paper is the following. Discussion on the computation model is situated in Section 2. We present the quantum subroutine that compares two strings in Section 3. Then, we discuss three problems: Strings Sorting problem in Section 4, the Most Frequent String Search problem in Section 5, and Intersection of Two String Sequences problem in Section 6. Section 7 contains the conclusions.
