Noisy Tree Data Structures and Quantum Applications

The paper presents a technique for constructing noisy data structures called a walking tree. We apply it for a Red-Black tree (an implementation of a Self-Balanced Binary Search Tree) and a segment tree. We obtain the same complexity of the main operations for these data structures as in the case without noise (asymptotically). We present several applications of the data structures for quantum algorithms. Finally, we suggest new quantum solution for strings sorting problem and show the lower bound. The upper and lower bounds are the same up to a log factor. At the same time, it is more effective than classical counterparts.


Introduction
Tree data structures are well-known and used in different algorithms.At the same time, when we construct algorithms with random behavior like randomized and quantum algorithms, we should consider error probability.We suggest a general method for updating a tree data structure in the noisy case, and we call the method Walking tree.For a tree of height h, we consider an operation for processing all nodes from a root to a target node.Assume that the running time of the operation is O(h • T ), where T is processing-a-node running time.Then, in the noisy case, our technique allows us to do it with O(log(1/ε) + h • T ) running time, where ε is the error probability for the whole operation.Here we assume that navigation by the tree can have error probability.Note that the standard way to handle probabilistic navigation is the success probability boosting (repetition of the noisy action) with O(h • log(1/ε) + h • T ) complexity.
Our technique is based on results for the noisy Binary search algorithm from [13].The authors of that paper present an idea based on the random walk algorithm for a balanced binary tree that can be constructed for binary search algorithm.We generalize the idea for a tree with any structure that allows us to apply the method to a big class of tree data structures.Two examples of such data structures are presented in the next paragraph.Note that different algorithms for noisy search especially, a noisy tree and graph processing and search were considered in [37,22,12,11,9,6,10].
We apply the technique to two tree data structures.The first one is Red-Black tree [8] which is an implementation of self-balanced binary search tree [8].If the key comparing procedure has an error probability at most p < 0.5 − δ for some 0 < δ < 0.5, then our noisy self-balanced binary search tree allows us to do add, remove, and search operations in O(log(N/ε)) running time.Here ε is the error probability for a whole operation and N is the number of nodes in the tree.In the case of ε = 1/P oly(N ), we have O(log N ) running time.So, in that case, the noisy key comparing procedure does not affect running time (asymptotically).At the same time, if we use the success probability boosting technique, then the running time is O((log N ) 2 ).The second one is the Segment tree [32,31].If the indexes comparing procedure has an error probability at most p < 0.5 − δ for some 0 < δ < 0.5, then our noisy segment tree allows us to do update and request operations in O(log(N/ε)) running time, where ε is the error probability for a whole operation and N is the number of leaves.In the case of ε = 1/P oly(N ), we have O(log N ) running time.So, we obtain similar advantage.
We use these data structures in the context of quantum computation.Quantum computation [2,34,1,24,39,20] is one of hot topics in the last decades.Quantum algorithms have randomized behavior, so it is important to use noisy data structures for this model.We use the quantum query model [2,1,24] as the main computational model for the quantum algorithms.We use the Walking tree method to solve the following problems.
The first problem is the String Sorting problem.Assume that we have n strings of length l.We want to sort them in lexicographical order.It is known [18,19] that no quantum algorithm can sort arbitrary comparable objects faster than O(n log n).At the same time, several researchers tried to improve the hidden constant [36,35].Other researchers investigated the space-bounded case [28].We focus on sorting strings.In the classical case, we can use an algorithm that is better than arbitrary comparable objects sorting algorithms.It is Radix sort that has O(nl) query complexity [8] for a finite-size alphabet.It is also a lower bound for classical (randomized or deterministic) algorithms that is Ω(nl).There is a quantum algorithm [23,25] for the string sorting problem that has query complexity O(n(log n) • √ l) = Õ(n √ l), where Õ does not consider log factors.We suggest a simpler implementation based on a noisy red-black tree.These algorithms show quantum speed-up.Additionally, we show the lower bound for quantum algorithms that is Ω(n √ l/ √ log n).So, the quantum solution is optimal up to a log factor.
The second problem is the Auto-Complete Problem.We have two kinds of queries: adding a string s to the dictionary S and querying the most frequent complement of a string t from the dictionary.We call s a complement of t if t is a prefix of s.Assume that L is the total sum of all lengths of strings from all queries.We solve the problem using quantum string comparing algorithm [3,23] and noisy Red-Black tree.The running time of the quantum algorithm is O( √ nL log n).The lower bound for quantum running time is Ω( √ L).At the same time, the best classical algorithm based on trie(prefix tree) [29] has O(L) running time.That is also the classical (deterministic or randomize) lower bound Ω(L).So, we obtain quantum speed-up if most of the strings have Ω((log n) 2 ) length.
The structure of this paper is as follows.Section 2 contains preliminaries.We present the main technique in Section 3. Section 4 contains a discussion of the noisy self-balanced binary search tree and the noisy segment tree.A discussion of String Sorting Problem is in Section 5, and a discussion of Auto-Complete Problem is in Section 6.

Preliminaries
f with non-Boolean arguments.It can be simulated by a Boolean-argumentfunction case using a binary representation of arguments.We refer the readers to [34,2,1,24] for more details on quantum computing.

Main Technique: A Walking Tree
In this section, we present a rooted tree that we call a walking tree.It is a utility data structure for noisy computation for the main data structure.Here we use it for the following data structures: (i) Binary Search Tree.We assume that elements comparing procedures can have errors.(ii) Segment Tree.We assume that an indexes (borders of segments) comparing procedure can have errors.
Note that the walking tree is a general technique, and it can be used for other tree data structures.Let us present the general idea of the tree.The technique is motivated by [13].Assume that we have a rooted tree G.We want to do an operation on the tree that is moving from the root to a specific (target) node of the tree.Assume that we have the following procedures: GetTheRoot(G) returns the root node of the tree G. SelectChild(v) returns the child of the node v ∈ V(G) that should be reached from the node v. IsItTheTarget(v) returns T rue if the node v ∈ V(G) is the last node that should be visited in the operation; and returns F alse otherwise.ProcessANode(v) processes the node v ∈ V(G) in the required way.IsANodeCorrect(v) returns T rue if the node v ∈ V(G) should be visited during the the operation; and returns F alse if the node is visited because of an error.
Assume that the operation has the following form (Algorithm 1).
Algorithm 1 An operation on the tree Let us consider the operation such that "navigation" procedures (that are SelectChild, IsANodeCorrect, and IsItTheTarget) can return an answer with an error p, where p < 0.5 − δ, where 0 < δ ≤ 0.5.We assume that error events are independent.Our goal is to do the operation with an error ε.Note that in the general case, ε can be non-constant and depend on the number of tree nodes.Let h = h(G) be the height of the tree.The standard technique is boosting success probability.On each step, we repeat SelectChild procedure O(log(h/ε)) times and choose the most frequent answer.In that case, the error probability of the operation is at most ε, and the running time of the operation is O(h log(h/ε) + h • T ), where T is complexity of ProcessANode procedure.

Our goal is to have
Let us construct a rooted tree W by G such that the set of nodes of W has a one-to-one correspondence to the nodes of G and the same with sets of edges.We call W a walking tree.Let λ W : V(W ) ↔ V(G) and λ G : V(G) ↔ V(W ) be bijections between these two sets.For simplicity, we define procedures for W similar to the procedures for G. Suppose u ∈ V(W ), then Note that the navigation procedures are noisy (have an error).We reduce the error probability to 0.1 by constant number of repetitions (using the boosting success probability technique).Additionally, we associate a counter c(u) with a vertex u ∈ V(W ) that is a non-negative integer number.Initially, values of counters are 0 for all nodes, i.e. c(u) = 0 for each u ∈ V(W ).
We invoke a random walk by the walking tree W .The walk starts from the root node GetTheRoot(W ).Let us discuss processing u ∈ V(W ).Firstly, we check the counter's value c(u).If c(u) = 0, then we do steps from 1.1 to 1.3.
Step 1.1.We check the correctness of current node using IsANodeCorrect(u) procedure.If the result is T rue, then we go to Step 1.2.If the result is F alse, then we are here because of an error, and we go up by changing u ← Parent(u).If the node u is the root, then we stay in u.
Step 1.2.We check whether the current node is target using IsItTheTarget(u) procedure.If it is T rue, then we increase the counter c(u) ← 1.If it is F alse, then we go to Step 1.3.
If c(u) > 0, then we do Step 2.1.We can say that the counter c(u) is a measure of confidence that u is the target node.If c(u) = 0, then we should continue walking.If c(u) > 0, then we think that u is the target node.If a bigger value of c(u) means we are more confident that it is the target node.
Step 2.1.If IsItTheTarget(u) = T rue, then we increase the counter c(u) ← c(u) + 1.Otherwise, we decrease the counter c(u) ← c(u) − 1.So, we become more or less confident in the fact that the node u is the target.
The walking process stops in s steps, where s = O(h+log(1/ε)).The stopping node u is the target one.After that, we do the operation with the original tree G.We store path in P ath = (v 1 , . . ., v k ), such that v k = λ W (u), v i = Parent(v i+1 ), and v 1 is the root node of G.Then, we process them using ProcessANode(v i ) for i from 1 to k.One step of the walking process on the walking tree W is presented in Algorithm 2 as a procedure OneStep(u) that accepts the current node u and returns the new node.The whole algorithm is presented in Algorithm 3.
Let us discuss the algorithm and its properties.On each node, we have two options, we go in the direction of the target node or the opposite direction.
Assume that c(u) = 0 of the current node u.If we are in a wrong branch, then the only correct direction is the parent node.If we are in the correct branch, then the only correct direction is the correct child node.All other directions are wrong.Assume that c(u) > 0. If we are in the target node, then the only correct direction is increasing the counter, and the wrong direction is decreasing the counter.Otherwise, the only correct direction is decreasing the counter.
Choosing the direction is based on the results of at most three invocations of navigation procedures (SelectChild, IsANodeCorrect, and IsItTheTarget).
Algorithm 2 One step of the walking process, OneStep(u).The input is u ∈ V(W ) and the result is the node for the next step of the walking.
Remember that we reach 0.1 error probability using a constant number of repetitions.Due independence of error events, the total error probability of choosing a direction is at most 0.3.So,the probability of moving in correct direction is at least 2/3 and for a wrong direction it is at most 1/3.Let us show that if s = O(h + log(1/ε)), then a error probability for an operation on G is ε Theorem 1. Suppose, s = O(h + log(1/ε)).Then, Algorithm 3 does the same action as Algorithm 1 with error probability ε ∈ (0, 0.5).(See Appendix A.) In the next section, we show several applications of the technique.

Noisy Binary Search Tree
Let us consider a Self-Balanced Search Tree [8].It is a binary rooted tree As an implementation of Self-Balanced Search Tree, we use Red-Black Tree [8,16].It allows us to add and remove a node with a specific value with O(log n) running time.Assume that the comparing procedure of two elements has an error p.Each operation (remove and add an element) has three steps: searching, doing the action (removing or adding), re-balancing.Re-balancing does not invoke Algorithm 3 The walking algorithm for s = O(h + log(1/ε)) steps.
Here • means the concatenation of two sequences.The line adds the node to the beginning of the path sequence k ← k + 1 ⊲ The length of the path sequence end while for i ∈ {1, . . .k} do ProcessANode(v i ) end for comparing operations, that is why it does not have an error.So, the only "noisy" procedure (can have an error) is searching.Let us discuss it.
Let us associate β(v) and γ(v) with a node v ∈ V(G).That are left and right bounds for α(v) with respect to the ancestor nodes.Formally, Here −∞ and +∞ are constants that are apriori less and more than any An error probability for the function is p < 0.5 − δ for some 0 < δ < 0.5.Let us present each of the required procedures for searching an object x operation.GetTheRoot(G) is for the root node of G.
The presented operations satisfy all requirements.Let us present the complexity result that directly follows from Theorem 1.
Theorem 2. Suppose the comparing function for elements of Red-Black Tree has an error p < 0.5 − δ for some 0 < δ < 0.5.Then, using the walking tree, we can do searching, adding and removing operations with O(log(n/ε)) running time and an error probability ε.
Corollary 1. Suppose the comparing function for elements of Red-Black Tree has an error p < 0.5 − δ for some 0 < δ < 0.5.Then, using the walking tree, we can do searching, adding, and removing operations with O(log n) running time and an error probability 1/P oly(n).

Noisy Segment Tree
We consider a standard segment tree data structure [32,31]  Update.Parameters are an index i and an element x (1 ≤ i ≤ n).The procedure assigns b i ← x.For this goal, we assign x for the leaf w that corresponds to the b i and update ancestors of w.
Request.Parameters are two indexes i and j (1 The main part of both operations is the following.For the given root node and an index i, we should find the leaf node corresponding to b i .The main step is the following.If we are in a node v with associated segment (b lef t , . . ., b right ), then we compare i with a middle element mid = ⌊(lef t + right)/2⌋ and choose the left or the right child.Assume that we have a comparing function for indexes Compare(a, b) that returns −1 if a < b; +1 if a > b; 0 if a = b.The comparing function returns the answer with an error p < 0.5 − δ for some 0 < δ < 0.5.
Let us present each of the required procedures for searching the leaf with index i in a segment tree G. GetTheRoot(G) returns the root node of the segment tree G. Theorem 3. Suppose, the comparing function for indexes of a segment tree is noisy and has an error p < 0.5 − δ for some 0 < δ < 0.5.Then, using the walking tree, we can do update and request operations with O(log(n/ε)) running time and an error probability ε.
If we take ε = 1/P oly(n), then the "noisy" setting does not affect asymptotic complexity.
Corollary 2. Suppose, the comparing function for indexes of a segment tree is noisy and has an error p < 0.5 − δ for some 0 < δ < 0.5.Then, using the walking tree, we can do update and request operations with O(log n) running time and an error probability 1/P oly(n)

Analysis, Discussion, Modifications
There are different additional operations with a segment tree.One such example is the segment tree with range updates.In this modification, we can update the values b i for a range i ∈ {ℓ, . . ., r} by a value in one request.The reader can find more information in [31] and examples of applications in [27,26].The main operation with a noisy comparing procedure is the same.So, we can still use the same idea for such modifications of the segment tree.Therefore, we should not store the borders of a segment in a node, and we can compute them during the walk on the segment tree.Additionally, we should not construct the walking tree.We can keep it in mind and walk by the segment tree itself using only three variables: the lef t and right borders of the current segment and a counter if required.
If we have access to the full segment tree, including leaves, then we can do operations without the walking tree.We can use the noisy binary search algorithm [13] for searching the leaf that corresponds to the index i, and then process all the ancestors of the leaf.There are at least two useful scenarios for a noisy segment tree.
1. We have access only to the root and have no direct access to leaves.
2. The second one is the compressed segment tree.If initially, all elements of the array b are empty or neutral for the function f , then we can compress a subtree with one node with a label of a segment with empty elements.On each step, we do not store any subtree if it has only neutral elements.In that case, we store only a root of this tree and mark it as a subtree with neutral elements.It is reasonable if n is very big and storing the whole tree is very expensive.In that case, we can replace the noisy binary tree with the noisy self-balanced search tree from the previous section.The search tree stores the updated elements in leaves, and we can search the required index in this data structure.At the same time, the noisy segment tree uses much less memory with respect to the Remark 1.That is why a noisy segment tree is more effective in this case too.

Quantum Sort Algorithm for Strings
As one of the interesting applications, we suggest applications from quantum computing [34,2,1,24].As objects with noisy comparing, we use strings.There is an algorithm for two strings t and s that compares them in O min(|s|, |t|) running time [25], where |s| and |t| are lengths of s and t respectively.The algorithm is based on modifications [30,21] of Grover's search algorithm [15,7].The result is the following
Let us take ξ = 0.1 and use the procedure as a string comparing procedure.We consider an application of the noisy search tree in this and in the next sections.Let us discuss the Strings Sorting problem as one of the applications.
Problem.There are n strings s 0 , . . ., s n−1 of size l for some positive integers n and l.The problem is to find a permutation (j 0 , . . ., j n−1 ) such that s ji < s ji+1 , or s ji = s ji+1 and j i < j i+1 for each i ∈ {0, . . ., n − 2}.
The Quantum sorting algorithm for strings was presented in [23,25].The running time of the algorithm is O(n √ l log n).We can present the algorithm with the same complexity but in a simpler way.Assume that we have a noisy self-balanced binary search tree with strings as keys and quantum comparing procedure from Lemma 1.We assume that the comparing procedure compares indexes in a case of equal strings.In fact, we store indexes of the strings in nodes.We assume that if a node stores a key index i, then any node from the left subtree has a key index j such that s j < s i or (s j = s i and j < i); and any node from the right subtree has a key index j ′ such that s j ′ > s i or (s j = s i and j ′ > i).Initially, the tree is empty.Let Add(i) be a function that adds a string s i to the tree.Let GetMin be a function that returns the index of the minimal string s from the tree according to the comparing procedure.After returning the index, the function removes it from the tree.The final algorithm is presented as Algorithm 4 and its complexity in Theorem 4. The second For-loop can be replaced by inorder traversal (dfs) of the tree for constructing the list.This approach has smaller hidden constant in big-O.The full idea is presented in Appendix B for completeness.The upper bound is complexity of the presented algorithm and algorithm from [25].The proof of the lower bound is presented in the next section.A reader can see that the difference between upper and lower bounds is just (log n) 1.5 .It shows that the presented algorithm is almost optimal.
Note that in the case of l = 1, the function RADIX n,1 can be used to compute the majority function.We use RADIX n,1 to sort strings and the n/2-th string is a value of the majority function.Therefore, we expect that complexity of RADIX n,1 should be Ω(n) [4].In the case of n = 2, the function RADIX 2,l is similar to the OR function, so we expect that it requires Ω( √ l) queries [4].The formal proof for relations between these functions is presented in Appendix C.
We denote M the spectral norm of a matrix M , and A • B denotes the Hadamard product of matrices A and B: We prove a lower bound for RADIX using Adversary method [17].
Theorem 5 (Adversary bound, [17]).Let f : {0, 1} n → Σ O be an arbitrary function, where Σ O is a set of outputs.Let A be an arbitrary matrix with rows and columns indexed by input strings, such that A(σ, τ ) = 0 if f (σ) = f (τ ).Let D i be a zero-one matrix with rows and columns indexed by input strings, such that D i (σ, τ ) = 1 iff these strings differ in i-th symbol: , where the maximum is taken over all matrices A with non-negative entries.Then the two-sided ǫ-bounded error quantum query Bounds obtained by using Adversary method can be composed.It is a nice property that we use.
To obtain an upper bound on A • D i , the following lemma is used.

Lemma 2 ([38]
). Assume A, B and C are real matrices such that A = B • C.Then, A ≤ max i,j:A(i,j) =0 r i (B)c j (C), where r i (B) is the ℓ 2 -norm of the i-th row of B, and c j (C) is the ℓ 2 -norm of the j-th column of C.
Firstly, let us note that sorting a list cannot be easier than computing the sign of permutation that sorts that list.We prove it in Lemma 3.For positive integers n, l, let SGN n,l : {0, 1} nl → {0, 1} be a function that for n binary strings of length l returns whether the permutation that sorts the input list is odd or even.Let s 0 , . . ., s n−1 ∈ {0, 1} l be input strings.Then SGN n,l (s 0 , . . ., s n−1 ) = sgn(RADIX n,l (s 0 , . . ., s n−1 ).Here sgn(j 0 , . . ., j n−1 ) is 0 if the permutation (j 0 , . . ., j n−1 ) is even, and 1 otherwise.A permutation is even iff the number of inversions in the permutation is even.See [14] for more details.
Lemma 3. Computing RADIX n,l is not easier than computing SGN n,l : We restrict input for SGN as follows (restricting input cannot make computing SGN easier).Let us interpret an n×l zero-one input matrix as a combination of l/ log 2 n bands of zeroes and ones of size n × log 2 n.We can interpret each band as a list of n numbers from 0 to n − 1, because log 2 n bits are enough to encode these numbers.Let us call a band proper if it either contains a permutation (e.g. it contains each number from 0 to n − 1 exactly once) or it contains only zeroes.We consider only inputs for SGN that are composed from proper bands.Let SG n : {0, 1} n log n → {0, 1, ⊥} be a function that gets a proper band of n words of log n symbols and returns either a sign of permutation, or ⊥ if all words are equal.Here by a sign of permutation, we mean the result of sgn function.Let FST m : {0, 1, ⊥} m → {0, 1} be a function that gets m symbols and returns the first symbol that is not equal to ⊥.If all arguments are equal to ⊥, then FST m returns 0. It is easy to see that the following holds Lemma 4. SGN n,l = FST l/ log n • SG n , . . ., SG n , where each SG n acts on its own band.(See Appendix E).
We can obtain Adversary bound for the introduced functions.
Finally, we apply Theorem 3 to Lemmas 5 and 6.
Lemma 7. The following statement is right ADV(SGN n,l ) = Ω(n l/ log n).
Using this lemma and Theorem 5 we obtain the lower bound for the string sorting problem.
Theorem 6.The following statement is right Q(RADIX n,l ) = Ω(n l/ log n).

Auto-Complete Problem
Problem.Assume that we use some constant size alphabet, for example, binary, ASCII or Unicode.We work with a sequence of strings S = (s i1 , . . ., s i |S| ), where |S| is the length of the sequence; and i j are increasing indexes of strings.In fact, the index i j is the index of the query for adding this string to S. Initially, the sequence S is empty.Then, we have n queries of two types.The first type is adding a string s to the sequence S. Let #(u) = |{j : u = s j , j ∈ {i 1 , . . ., i |S| }}| be a number of occurrence (or "frequency") of a string u among S.The second type is querying the most frequent complement from S of a string t.Let us define it formally.If t is a prefix of s j , then we say that s j is a complement of t.Let D(t) = {s j : j ∈ {i 1 , . . ., i |S| }, s j is a complement of t} be the set of complements for t, and let md(t) = max{#(s r ) : r ∈ {i 1 , . . ., i |S| }, s r ∈ D(t)} be the maximal "frequency" of strings from D(t).The problem is to find the index mi(t) = min{r : r ∈ {i 1 , . . ., i |S| }, s r ∈ D(t), #(s r ) = md(t)}.
Here we present the main idea of a solution and a full description of the algorithm is presented in Appendix H.
We use a Self-Balanced Search tree for our solution.A node v of the tree stores 4-tuple (i, c, j, jc), where i is an index of a string s i that is "stored" in the node, and c = #(s i ).The tree is a Search tree by this strings s i similar to storing strings in Section 5.For comparing strings, we use a quantum procedure from Lemma 1.Therefore, our tree is noisy.The index j is the index of the most "frequent" string in the sub-tree which root is v, and jc = #(s j ).Formally, for any vertex v ′ from this sub-tree if (i ′ , c ′ , j ′ , jc ′ ) is associated with v ′ , then c ′ < jc or (c ′ = jc and i ′ ≥ j).
Initially, the tree is empty.Let us discuss processing the first type of queries.We want to add a string s to S. We search a node v with associated (i, c, j, jc) such that s i = s.If we can find it, then we increase c ← c + 1.It means j parameter of the node v or its ancestors can be updated.There are at most O(log n) ancestors because height of the tree is O(log n).So, for each ancestor of v that associated with (i ′ , c ′ , j ′ , jc ′ ), if jc ′ < c or (jc ′ = c and j ′ > i), then we update j ′ ← i and jc ← c.
If we cannot find the string s in S, then we added a new node to the tree with associated 4-tuple (r, 1, r, 1), where r is the index of the query.Note that if we re-balance nodes in the red-black tree, then we easily can recompute j and jc elements of nodes.
Let us discuss processing the second type of queries.All strings s i that can be complement for t belongs to the set C(t) = {s r : r ∈ {i 1 , . . ., i |S| }, s r ≥ t and s r < t ′ }.Here we can obtain t ′ from the string t by replacing the last symbol by the next symbol from the alphabet.Formally, if t = (t 1 , . . ., t |t|−1 , t |t| ), then t ′ = (t 1 , . . ., t |t|−1 , t ′ |t| ), where the symbol t ′ |t| succeeds t |t| in the alphabet.We can say, that C(t) = D(t).The query processing consist of three steps.
Step 1.We search for a node v Rt such that t should be in the left sub-tree of v and t ′ should be in the right sub-tree of v. Formally, β(v Rt ) ≤ t ≤ α(v Rt ), and α(v Rt ) < t ′ ≤ γ(v Rt ).In the next two steps, we compute the index of the required string j ans and jc ans = #(s jans ).
Step 2. Let us look to the left sub-tree with t.Let us find a node v L that contains an index i L of the minimal string s iL ≥ t.Then, we go up from this node.Let us consider a vertex v.If it is the right child of Parent(v), then it is bigger than the string from Parent(v) and the left child's sub-tree, so we do nothing.If it is the left child of Parent(v), then it is less than the string from Parent(v) and all strings from the right child's sub-tree, so we update j ans and jc ans by values from the parent node and the right child.Formally, if (i p , c p , j p , jc p ) for the Parent(v) node and (i r , c r , j r , jc r ) for the right child node, then we do the following actions.If c p > jc ans or (c p = jc ans and i p < j ans ), then j ans ← i p and jc ans ← c p .If jc r > jc ans or (jc r = jc ans and j r < j ans ), then j ans ← j r and jc ans ← jc r .
Step 3. Let us look to the right sub-tree with t ′ .Let us find a node v R that contains an index i R of the maximal string s iR < t ′ .Then, we go up from this node and do the symmetric actions as in Step 2.
Each of these three steps requires O(log n) running time because each of them observes nodes of a single branch.Finally, we obtain quantum complexity of the problem.
Theorem 7. The quantum algorithm with a noisy Self-Balanced Search tree for Auto-Complete Problem has O( √ nL log n) running time and error probability 1/3, where L is the sum of lengths of all queries.Additionally, the lower bound for quantum running time is Ω( √ L). (See Appendix H).
Let us consider the classical (deterministic or randomize) case.If we use the same Self-balanced search tree, then the running time is O(L log n).At the same time, if we use the Trie (prefix tree) data structure [29], then the complexity is O(L).We can show that it also the lower bound for classical case.
Lemma 8.The classical running time for Auto-Complete Problem is Θ(L), where L is the sum of lengths of all queries.(See Appendix H).
If O(n) strings have length at least Ω((log 2 n) 2 ), then we obtain a quantum speed-up.

Conclusion
We suggest the Walking tree technique for noisy tree data structures.We apply the technique to the Red-black tree and the Segment tree.We show that the complexity of the main operations is asymptotically equal to the complexity of standard (not noisy) versions of the data structures.We use noisy Red-black tree for two problems: The Strings Sorting Problem and The Auto-Complete Problem.The considered algorithms are quantum because they use the quantum string comparing algorithm as a subroutine.This subroutine demonstrates quadratic speed-up, but it has a non-zero error probability.For the String Sorting Problem, we show lower and upper bounds that are the same up to a log factor.For Auto-Complete Problem, we obtain quantum speed-up for the problems if (log n) 2 = o(l) where n is the number of queries and l is the size of an input string of a query.
Future work can be applying the Walking tree technique to other tree data structures and obtain the noisy version of them with good complexity of main operations.Also, it is interesting to find more applications for noisy data structures.We assume that quantum algorithms should be one of the fruitful fields for such applications.It is interesting to meet quantum lower and upper bounds for considered problems.
Proof.Let us consider the walking tree.We emulate the counter by replacing it with a nodes chain of length s + 1. Formally, for a node u ∈ V(W ) we add . ., s} and d u s+1 does not have children.
In that case the increasing of c(u) can be emulated by moving from d u c(u) to d u c(u)+1 .The decreasing can be emulated by moving from d u c(u) to d u c(u)−1 .We can assume that d u 0 is the node u itself.Let u target be the target node, i.e.IsItTheTarget(u target ) = T rue.Let us consider the distance L between the target node d Let X i = (Y i + 1)/2 for i ∈ {1, . . ., s}.We treat X 1 , . . ., X s as independent binary random variables.Let X = s i=1 X i .For such X and for any 0 < δ ≤ 1, the following form of Chernoff bound [33] holds Since Pr[X i = 1] = Pr[Y i = +1] = 2/3, we have E[X] = 2s/3 and the inequality (1) becomes Substituting Y for X we get From now on without loss of generality, we assume that s = ⌈c•(h+log(1/ε))⌉ for some c > 0. Let δ = 1  6 and c ≥ 108.
In the following steps, we relax the inequality by obtaining less tight bounds for the target probability.
Firstly, we obtain a new lower bound and hence Secondly, we obtain a new upper bound Combining the two obtained bounds we have and hence Pr[Y < h] < ε.
Considering the probability of the opposite event we finally get B Quantum Sorting Algorithm.Second Approach Assume that we want to construct have a result list.We use list variable as a result.
We use the recursive procedure GetListByTree(v) for in-order traversal (dfs) of the searching tree.Here v is the processing node.Assume that we have GetTheLeftChild(v) for obtaining the left child of v, GetTheRightChild(v) for obtaining the right child of v; GetIndexOfString(v) for obtaining the index of the string α(v) that is stored in v.The procedure is presented in Algorithm 5.
The total sorting algorithm is Algorithm 6.
C Complexities of RADIX n,1 and RADIX 2,l This section contains a formal statement and proof for the note in the beginning of Section 5.1 that reads as follows.
Note that in the case of l = 1, the function RADIX n,1 can be used to compute the majority function.We use RADIX n,1 to sort strings and the n/2-th string Proof.We can compute SGN by computing the sign of the permutation that is a result of computing RADIX.It requires no call to the oracle, we can simulate the classical algorithm for computing the sign of the permutation.

E Proof of Lemma 4
Lemma 4. SGN n,l = FST l/ log n • SG n , . . ., SG n , where each SG n acts on its own band.
Proof.Consider an input w = (w 1 , w 2 , . . ., w l/ log n ) for SGN n,l , where each w i is a proper band, i.e. either w i = 0 = (0, . . ., 0) or The statement of the lemma is that SGN n,l (w) = FST l/ log n (SG n (w 1 ), SG n (w 2 ), . . ., SG n (w l/ log n )) for every choice of proper bands w i .
Let us define a matrix A with rows and columns indexed by strings from I = {0, 1, ⊥} m as follows.
A(σ, τ ) = 1, if σ = ⊥ m and τ = ⊥ m i →1 for some i ∈ {1, . . ., m}, 0, otherwise Problem.Assume that we use some constant size alphabet, for example, binary, ASCII or Unicode.We work with a sequence of strings S = (s i1 , . . ., s i |S| ), where |S| is the length of the sequence; and i j are increasing indexes of strings.In fact, the index i j is the index of the query for adding this string to S. Initially, the sequence S is empty.Then, we have n queries of two types.The first type is adding a string s to the sequence S. Let #(u) = |{j : u = s j , j ∈ {i 1 , . . ., i |S| }}| be a number of occurrence (or "frequency") of a string u among S.The second type is querying the most frequent complement from S of a string t.Let us define it formally.If t is a prefix of s j , then we say that s j is a complement of t.Let D(t) = {s j : j ∈ {i 1 , . . ., i |S| }, s j is a complement of t} be the set of complements for t, and let md(t) = max{#(s r ) : r ∈ {i 1 , . . ., i |S| }, s r ∈ D(t)} be the maximal "frequency" of strings from D(t).The problem is to find the index mi(t) = min{r : r ∈ {i 1 , . . ., i |S| }, s r ∈ D(t), #(s r ) = md(t)}.
We use a Self-Balanced Search tree for our solution.A node v of the tree stores 4-tuple (i, c, j, jc), where i is an index of a string s i that is "stored" in the node, and c = #(s i ).The tree is a Search tree by this strings s i similar to storing strings in Section 5.For comparing strings, we use a quantum procedure from Lemma 1.Therefore, our tree is noisy.The index j is the index of the most "frequent" string in the sub-tree which root is v, and jc = #(s j ).Formally, for any vertex v ′ from this sub-tree if (i ′ , c ′ , j ′ , jc ′ ) is associated with v ′ , then c ′ < jc or (c ′ = jc and i ′ ≥ j).
Initially, the tree is empty.Let us discuss processing the first type of queries.We want to add a string s to S. We search a node v with associated (i, c, j, jc) such that s i = s.If we can find it, then we increase c ← c + 1.It means j parameter of the node v or its ancestors can be updated.There are at most O(log n) ancestors because height of the tree is O(log n).So, for each ancestor of v that associated with (i ′ , c ′ , j ′ , jc ′ ), if jc ′ < c or (jc ′ = c and j ′ > i), then we update j ′ ← i and jc ← c.
If we cannot find the string s in S, then we added a new node to the tree with associated 4-tuple (r, 1, r, 1), where r is the index of the query.Note that if we re-balance nodes in the red-black tree, then we easily can recompute j and jc elements of nodes.
Assume that we have a Search(s) procedure that returns a node v with associated (i, c, j, jc) where s = s i .If there is no such a node, then the procedure returns N U LL.A procedure AddAString(r) adding a node (r, 1, r, 1) to the tree.A procedure GetTheRoot returns the root of the search tree.The processing of the first type of queries is presented in Algorithm 7 Let us discuss processing the second type of queries.All strings s i that can be complement for t belongs to the set C(t) = {s r : r ∈ {i 1 , . . ., i |S| }, s r ≥ t and s r < t ′ }.Here we can obtain t ′ from the string t by replacing the last symbol by the next symbol from the alphabet.Formally, if t = (t 1 , . . ., t |t|−1 , t |t| ), then t ′ = (t 1 , . . ., t |t|−1 , t ′ |t| ), where the symbol t ′ |t| succeeds t |t| in the alphabet.We can say, that C(t) = D(t).The query processing consist of three steps.
Step 1.We search for a node v Rt such that t should be in the left subtree of v and t ′ should be in the right sub-tree of v. Formally, β(v Rt ) ≤ t ≤ left child's sub-tree, so we do nothing.If it is the left child of Parent(v), then it is less than the string from Parent(v) and all strings from the right child's subtree, so we update j ans and jc ans by values from the parent node and the right child.Formally, if (i p , c p , j p , jc p ) for the Parent(v) node and (i r , c r , j r , jc r ) for the right child node, then we do the following actions.If c p > jc ans or (c p = jc ans and i p < j ans ), then j ans ← i p and jc ans ← c p .If jc r > jc ans or (jc r = jc ans and j r < j ans ), then j ans ← j r and jc ans ← jc r .This idea is presented in Algorithm 8 Step 3. Let us look to the right sub-tree with t ′ .Let us find a node v R that contains an index i R of the maximal string s iR < t ′ .Then, we go up from this node and do the symmetric actions as in Step 2.
Each of these three steps requires O(log n) running time because each of them observes nodes of a single branch.The complexity of the quantum algorithm is presented in Theorem 7. Before presenting the theorem, let us present a lemma that helps us to prove quantum and classical lower bounds.
Lemma 10.Auto-complete problem at least as hard as unstructured search 1 among O(L) bits.
Proof.Assume that the alphabet is binary.For any other case we just consider two letter from the alphabet.Assume that all strings from queries of the first type have length k.
Lemma 10 we obtain the required lower bound.
Let us consider the classical (deterministic or randomize) case.If we use the same Self-balanced search tree, then the running time is O(L log n).At the same time, if we use the Trie (prefix tree) data structure [29], then the complexity is O(L).
We store all string of S in the trie.For each terminal node we store "frequency" of the corresponding string.For each node v (even non-terminal) that corresponds to a string u as a path from the root to v, additionally to the regular information we store the index of required complement for t and its frequency.When we process the first type of query, we update the frequency in the terminal node and update additional information in all ancestor nodes because they store all possible prefixes of the string.For processing the query of the second type, we just find the required node and take the answer in the additional information of the node.
We can show that it also the lower bound for classical case.Lemma 8.The classical running time for Auto-Complete Problem is Θ(L), where L is the sum of lengths of all queries.
Proof.Let us start with the upper bound.Similarly to the proof of Theorem 7, we can show that the running time of processing a query of both types is O(|s|) or O(|t|) depends on the type of a query.Let m 1 , . . ., m n be lengths of strings from queries.So, the total complexity is O(m Let us discuss the lower bound.It is known [5] that the classical running time for the unstructured search among O(L) variables is Ω(L).So, due to Lemma 10 we obtain the required lower bound.
If O(n) strings have length at least Ω((log 2 n) 2 ), then we obtain a quantum speed-up.
for an array b = (b 1 , . . ., b n ) for some integer n > 0. The segment tree is a full binary tree such that each node corresponds to a segment of the array b.If a node v corresponds to a segment (b lef t , . . ., b right ), then we store a value α(v) that represents some information about the segment.Let us consider a function f such that α(v) = f (b lef t , . . ., b right ).A segment of a node is the union of segments that correspond to its two children.Typically, the children correspond to segments (b lef t , . . ., b mid ) and (b mid+1 , . . ., b right ), for mid = ⌊(lef t + right)/2⌋.We consider α(v) such that it can be computed by values of two children α(v l ) and α(v r ), where v l and v r are left and right children of v. Leaves correspond to single elements of the array b.As an example, we can consider integer values b i and sum α(v) = b lef t + • • • + b right as the value in a vertex v and a corresponding segment (b lef t , . . ., b right ).The data structure allows us to invoke the following requests in O(log n) running time.
For mid = ⌊(lef t+right)/2⌋, and the segment (b lef t , . . ., b right ) associated with a node v, the function SelectChild(v) returns the left child of v if Compare(mid, i) ≤ 0; and returns the right child othewrwise.IsItTheTarget(v) returns T rue if lef t = i = right, formally, Compare(lef t, i) = 0 and Compare(right, i) = 0; and returns F alse otherwise.Here the segment (b lef t , . . ., b right ) is associated with v. ProcessANode(v) recomputes α(v) = f (b lef t , . . ., b right ) according to the values of α in the left and the right children.IsANodeCorrect(v) returns T rue if lef t ≤ i ≤ right, formally, Compare(lef t, i) ≤ 0 and Compare(x, right) ≤ 0; and returns F alse otherwise.Here the segment (b lef t , . . ., b right ) is associated with v.The presented operations satisfy all requirements.Let us present the complexity result that directly follows from Theorem 1.

Remark 1 .
If the segment tree is constructed for an array b 1 , . . ., b n , then we can extend it to b 1 , . . ., b n , . . ., b k , where k = 2 ⌈log 2 n⌉ that is closest to n power of 2 and b n+1 , . . ., b k are neutral element for the function f .If we have a vertex v and two borders lef t and right of the segment associated with v, then we always can compute the segments for the left and the right children that are b lef t , . . ., b mid and b mid+1 , . . ., b right for mid = (lef t + right)/2.Additionally, we can compute the segment for the parent that is b lef t , . . ., b pright , where pright = 2•right−lef t if the node is the left child of its parent.If the node is the right child of its parent, then the parent's segment is b plef t , . . ., b right , where plef t = 2 • lef t − right.

Algorithm 4 Theorem 4 .
Quantum string sorting algorithm for i ∈ {0, . . ., n − 1} do Add(i) end for for i ∈ {0, . . ., n − 1} do ji ← GetMin end for The quantum running time for sorting n string of size l is O(n √ l log n) and Ω(n √ l/ log n).
utarget s+1and the current node in the modified tree.The distance L is a random variable.Each step of the walk increase or decrease the distance L by 1. So, we can present L = dist(root, d utarget s+1 ) − Y , where root is the root node of W , Y = (Y 1 + • • • + Y s ), and Y i ∈ {−1, +1} are independent random variables that represent i-th step and show increasing or decreasing the distance.Let Y i = +1 if we move in the correct direction, and Y i = −1 if we move in the wrong direction.Note that the probability of moving to the correct direction (Y i = +1) is at least 2/3 and the probability of moving to the wrong direction (Y i = −1) is at most 1/3.From now on without loss of generality, we assume that Pr[Y i = +1] = 2/3 and Pr[Y i = −1] = 1/3.If L ≤ s, then we are in the d utarget i node in the modified tree and in the u target node in the original walking tree W .Note that dist(root, d utarget s+1 ) ≤ h + s, where h = h(W ) by the definition of the height of a tree.Therefore, L ≤ s means Y = Y 1 + • • • + Y s ≥ h.So, the probability of success of the operation is the probability of the Y ≥ h event, i.e.Pr success = Pr[Y ≥ h].