On quantum methods for machine learning problems part I: Quantum tools

This is a review of quantum methods for machine learning problems that consists of two parts. The first part, “quantum tools”, presents the fundamentals of qubits, quantum registers, and quantum states, introduces important quantum tools based on known quantum search algorithms and SWAP-test, and discusses the basic quantum procedures used for quantum search methods. The second part, “quantum classification algorithms”, introduces several classification problems that can be accelerated by using quantum subroutines and discusses the quantum methods used for classification.


Introduction
Machine Learning (ML) is a rapidly developing area of computer science, motivated by a sharp growth in the volume of data that is being transferred, stored, and processed on a daily basis. Quantum methods bring new ideas and approaches to machine learning problems. Over the last decade, several survey and tutorial papers have been published by mathematicians with a variety of backgrounds in computer science, placing emphasis on different machine learning problems. These papers present several aspects of the application of quantum methods in machine learning [1][2][3][4] .
In this review, we focus on two main problems of machine learning, namely the classification problem and the clustering problem. Classification is associated with learning algorithms that group data according to certain criteria, while clustering aims to find inherent patterns in the data. In this paper, we consider classification as the process by which algorithms group data based on predefined characteristics, which is known as supervised learning. Clustering, on the other hand, is the process of grouping data without predefined characteristics, which is known as unsupervised learning.
We present the basic quantum methods, such as the Grover quantum search and its variants as fundamental tools. We then demonstrate how these quantum tools can be useful for accelerating the computations of classification and clustering problems. Rather than attempting to cover all known classification and clustering problems for which quantum subroutines can be useful, we have chosen what we consider to be typical tasks as references to demonstrate the power of quantum subroutines.
The first part of the review is organized as follows. First, we present the basic notions and formalizations of qubits and quantum registers, and the quantum states of qubits and quantum registers. We show the difference between the classical and quantum registers and their states, and define the transformations of the quantum states of quantum registers and methods for the extraction of information. We present the quantum circuit, quantum query algorithm model, and quantum branching program as models for the realizations of quantum algorithms. In the main section, we present the basic quantum procedures used in quantum search algorithms. We not only give a formal description of the procedures, but also present them in a form that can be used for constructing classification problems and present recent sources for readers to find realizations of such procedures.

Quantum Computing Basics
In this section, we present the basic notions of quantum computations as found in Ref. [5]. Jozsa [6] also provided some excellent notes on quantum computations.

Qubit
The notion of quantum bit (qubit) is the basis of quantum computations. Qubit is the quantum version of the classical binary bit physically realized with a two-state device. Just like a binary digit, there are two possible outcomes for the measurement of a qubit: the value 0 or 1. Whereas the state of a classical bit can only be either 0 or 1, the general state of a qubit according to quantum mechanics can be any coherent superposition of both, which allows computation on 0 and 1 simultaneously. Such a phenomenon is known as the quantum parallelism.
Formally, a qubit's state is a column vector j i from the two-dimensional Hilbert space H 2 , i.e., where vectors j0i and j1i are the orthonormal bases of H 2 , and˛;ˇ2 C such that j˛j 2 C jˇj 2 D 1. Numbers andˇare called amplitudes. The Bloch sphere is a representation of a qubit's state as a point on a three-dimensional unit sphere (see Fig. 1). Consider a qubit in state j i such that j˛j 2 C jˇj 2 D 1, we can then represent amplitudes as (2) where i is the imaginary unit, is the azimuthal angle, and Â is a polar angle of a point on the bloch spere in Fig. 1. If we consider only real values for˛andˇ, then the state of a qubit is a point on a unit circle (see Fig. 2). Thus, in the case of real-valued amplitudes, the state of a qubit is j i D cos Â j0i C sin Â j1i , Â 2 OE0; 2 / (3)

States of quantum registers
A quantum register is an isolated quantum mechanical system composed of n qubits (a quantum n-register). A quantum n-register can represent the superposition of 2 n states. This allows us to compute on 2 n states simultaneously. This phenomenon of quantum parallelism is a potential advantage of quantum computational models. Formally, a quantum state j i of a quantum nregister is described as follows. Let D 1 2 n be a binary sequence. Then the tensor product j 1 ij 2 i˝ ˝j n i is denoted by j i. Let Basis D fj00 0i, j00 1i, : : : ; jbi n.i 1/i ; : : : ; j11 1ig be a set of orthonormal vectors, where bi n.i/ is a binary representation of i . Basis forms a basis for 2 n dimensional Hilbert space H 2 n . The basis vectors from Basis can also be represented in brief as j0i ; : : : ; j2 n 1i. Usually, Basis is usually referred to as computational basis.
A quantum state j i of a quantum n-register is a complex valued unit vector in 2 n -dimensional Hilbert space H 2 n that is described as a linear combination of basis vectors jii, i 2 f0; : : : ; 2 n 1g: where j˛i j 2 expresses the probability to find the nregister in state ji i when state j i is measured with regard to Basis. We say that state j i is in the superposition of basis vector ji i with amplitude˛i . We will also use the notation .H 2 /˝n for Hilbert space H 2 n to outline the fact that vectors are the states of a quantum n-register. If a state j i 2 .H 2 /˝n can be decomposed to the tensor product of several single qubits, i.e., j i D j 1 i˝j 2 i˝ ˝j n i, j i, it is considered "not entangled". Otherwise, if the state can not be decomposed to the tenser product of several single qubits, it is called "entangled". An example of entangled states are Einstein, Podolsky, and Rosen (EPR)-pairs.

Transformations of quantum states
Quantum mechanics postulates that transformations of quantum states j i 2 .H 2 /˝n (of a quantum n-register) are mathematically determined by unitary operatorš 0˛D U j i where U is a 2 n 2 n unitary matrix. Such a unitary transformation is acting on the quantum n-register. A unitary matrix U can be written in the exponential form U D e iW (6) where W is a Hermitian matrix [7] .

Basic transformations of quantum states
Below are several basic transformations (unitary matrices).
I is an identity operator. That is, X is a NOT operator. NOT flips the state of a qubit. It is a special case of R O x .Â /-a rotation around the Xaxis of the Bloch sphere by .
S and T are phase transformation operators. 8 They are special cases of the rotation around the Zaxis of the Bloch sphere: S is rotation by 2 and T is rotation by 4 .
z is the Pauli-Z gate. It is a special case of R O z .Â /-a rotation around the Z-axis of the Bloch sphere by .
H is a Hadamard operator. It is the combination of two rotations: around the Z-axis of the Bloch sphere by and around the Y -axis of the Bloch sphere by 2 .

<
: The j1i ; applying of the Hadamard operator to this qubit allows for the transfer of phase information into amplitudes. After applying the Hadamard gate to j 0 i, we obtain j 1 i D H j 0 i D cos j0i C sin j1i.

Quantum circuits
Circuit is a simple and visual way of representing a sequence of transformations of register states. A classical Boolean circuit is a finite directed acyclic graph with AND, OR, and NOT gates. It has n input nodes, which contain n input bits (a state of nregister). The internal nodes are AND, OR, and NOT gates, and there are one or more designated output nodes. The initial input bits are fed into AND, OR, and NOT gates according to the circuit, and eventually the output nodes assume some values. A circuit computes a Boolean function f W f0; 1g n ! f0; 1g m , if the output nodes get the value f . / for every input 2 f0; 1g n .
A quantum circuit (also called a quantum network or quantum gate array) acting on the quantum register is a realization of the transformation of quantum states (states of a quantum register). A quantum circuit generalizes the idea of the classical circuit, replacing the AND; OR, and NOT gates with elementary operators (quantum gates). A quantum gate is a unitary operator on a small (usually 1, 2, or 3) number of qubits. Mathematically, if gates are applied in a parallel way to different parts of the quantum register, then they can be composed by taking tensor products. If gates are applied sequentially, then they can be composed by taking the ordinary product. Figure 3 illustrates the Hadamard operator (or gate) and Fig. 4 illustrates the NOT or X gate. If the rectangle of a gate crosses a line of a qubit then the gate is applied to this qubit. If the rectangle crosses several lines of qubits, then it is applied to all of these qubits.
Controlled quantum transformation. Controlled operator C q .U / (the quantum "if then else" operator) is implemented by a unitary transformation U that is applied only if some condition for q qubits is fulfilled. Supposing that qubits jc 1 i, jc 2 i ; : : : ;ˇc qą re in one of basis states fj0i ; j1ig, Fig. 5 shows a quantum circuit that implements operator C q .U /, which applies a unitary transformation U controlled by jc 1 i, jc 2 i ; : : : ;ˇc q˛q ubits with the condition that all controlling qubits are in state j1i. This condition is represented on the circuit diagram in Fig. 5 by black points. This operator can be represented as C q .U / jc 1 i jc 2 i ˇc q˛j i D jc 1 i jc 2 i ˇc q˛U j i (13) If all the control qubits are in state j1i, the (unitary) transformation U is applied. If one qubit is in state j0i, the identical transformation is applied.
The quantum circuit shown in Fig. 6 generalizes the above controlled quantum transformation. Supposing     that we need to apply transformation U for j i with the condition that c 1 D 0; c 2 D 1; : : : ; c q D 0, such a circuit is shown on the left side of Fig. 6. The white and black points describe the conditions of the controlling qubits (0 and 1) for applying transformation U for j i. The technical construction of such a circuit is shown on the right side of Fig. 6. The inversion operator X is added to those controlling qubits that should be 0. Operator U will then be applied if all controlling qubits are 1. After the operator U has been applied, we "return" the controlling qubits in their initial states.
Using this mechanism, an arbitrary control condition can be implemented. Such controlled transformations are key transformations for quantum algorithms. The controlled operator C q .U / itself can be expressed as a unitary matrix. Two basic controlled operators are CNOT and CCNOT (or 2CNOT).
The CNOT.a; b/ gate flips the second entry b (the target qubit) if and only if the first entry a (the control qubit) is j1i (see Fig. 7).
The CCNOT (or 2CNOT) is a Toffoli gate. The 2CNOT.a; b; c/ gate flips the third entry c (the target qubit) if and only if the first entry a and the second entry b (the control qubits) are j1i (see Fig. 8).
At the abstract level, quantum state transformations are described in terms of linear transformations of U . Such transformations are implemented by affecting the quantum register, which means that linear transformations of U are implemented by "controlled" actions of type O on the quantum register: Note that the quantum register can be prepared in some specific initial quantum state. A quantum algorithm acts on the quantum register to obtain the necessary quantum state.

Information extraction (measurement)
There is only one way to extract information from a state of a quantum n-register for the "macro" world, which is to measure the state of the quantum register. Measurement can also be considered as the second type of quantum operators, with unitary transformations being the first.
Different measurements are considered in quantum computation theory. In this review, we will use only a measurement in the respect of "computational basis". This measurement is described as follows. If we measure the quantum state P i˛i jii, then we get one of the basis states jii with a probability j˛i j 2 .
We can also perform partial measurement of the state of a quantum register. Considering the case of a quantum 2-register, let j i be a state of such a quantum 2-register: Imagining that we measure the first qubit of the 2register, the probability of getting j0i is the same as if we measure both qubits and sum over all of the probabilities of the j0i outcome on the first qubit: Pr.j0i/ D Pr.j00i/CPr.j01i/ D j˛0 0 j 2 Cj˛0 1 j 2 (15) The state of the second qubit after the measurement is In a similar way, we get the probability of getting 1.
The state of the second qubit after the measurement is Partial measurement of a state j i of a quantum nregister for n 2 is a direct generalization of the case of partially measuring state j i of the quantum 2-register to the quantum n-register case.

Computational Models and Complexity Measurements
The computational complexity is based on the formalization of computation models. This section defines the main computational models that are used for quantum search problems. The computational model oriented for Boolean functions is defined as Let X D fx 1 ; : : : ; x N g be a set of variables of function f . Note that the above computational model can be easily generalized for other general functions.

Decision trees and branching programs
We consider a deterministic version of the closely related Decision Tree (DT) and Branching Program (BP) models of computation [8] . They are closely related. Following are two versions of DTs and BPs for quantum generalization.

Graph representation
DT A is a directed leveled binary tree with a selected starting node (root node). All the nodes V of A are partitioned into levels V 1 ; : : : ; V`. Level V 1 contains the starting node. Nodes at level V i are connected to nodes at level V i C1 . At each node in the tree, a Boolean variable x 2 X is tested. Different from the DT model, the BP model is not a tree but a leveled acyclic directed graph in which there could be more than one in-going edges to a vertex at level V i from the vertices at level V i 1 .
The computation of a DT and a BP starts from the root node. At each node in the graph, a Boolean variable x 2 X is tested. Depending on the outcome of the query, the algorithm proceeds to the x D 0 child or the x D 1 child of the node. Leaf nodes are marked by "0" or "1". If for an input D 1 ; : : : ; N , the computation reaches a leaf node in the tree, it outputs the value of the function listed at this leaf node.
Usually, the DT model is used when seeking to minimize computational time (number of queries). The DT model can be arbitrarily wide. The BP model is typically used when seeking to minimize both computational time (number of queries) and memory (number of nodes).

Linear representation
Let S D fs 1 ; : : : ; s d g be a set of d -dimensional column-vectors, where s i is a vector with all components "0" except one "1" in the i -th position. We call vector s 2 S a state of A. State s at each level i , 1 i `represents a node (by "1" component) where A can be found at that level. Next, let X i Â X be a set of variables tested at level i. A transformation of state s at level i , 1 i ` 1, is described by a set Q i .X i / of matrices that depend on the values of variables X i tested at that level. State s .0/ 2 S is an initial state.
DT A can be formalized as A D hS; Q 1 .X 1 /; : : Computation on an input by A is presented as a sequence s .0/ ! s .1/ ! ! s .`/ of state transformations determined by the structure of A and input . Let s .i/ be the current state at level i , then the next state will be

Complexity measures
Time and space (memory) are the two main complexity measures used for computational models. For decision models of computation, the analogs of these complexity measures are query complexity and size complexity. Query complexity is the maximum number of queries that the algorithm can perform during computation, which is equal to the depth D.A/ that is the length of the longest path from the root to a leaf in the decision tree A. Size complexity is the width of A, denoted by dim.A/. In addition, bits are used to encode a state at levels of A, such that size.A/ D dlog 2 dim.A/e. For function f , the complexity measure D.f / refers to the minimum time needed for computing f , and both of dim.f / and size.f / refer to the space.

Quantum query algorithm
The Quantum Query Algorithm (QQA) is a generalization of the DT model. A QQA A for computing Boolean function f .X / is based on a quantum size.A/-register (on a quantum system composed of size.A/ qubits). With j start i as an initial state, the procedure of computation is determined by the sequence U 0 ; Q; U 1 ; : : : ; Q; U`of operators that are dim.A/ dim.A/ unitary matrices.
Algorithm A contains of two types of operators. Operators U i are independent of input X, while Q is the query-operator of a fixed form that depends on the tested input X. The algorithm consists of performing U 0 ; Q; U 1 ; : : : ; Q; U`on j start i and measuring the result, as shown in Fig. 9.
The algorithm computes f .X / on an input . The initial state j start i is transformed to a final quantum 9 Quantum query algorithm as a quantum circuit.
state j i that can be measured to get value f . /. The final state j i depends on the input , so j i can be represented as j i; the final state also depends on f . /, so j i can be represented as j .f . //i oř f . /˛. These are the notations used in the paper.

Quantum branching program
Quantum Branching Programs (QBPs) [9][10][11] are another known model of computations, and a generalization of the classical BP model. QBPs and QQAs are closely related, and each could be considered a variant of the other depending on the point of view. For example, in this paper, QBP can be considered as a variant of the QQA model, which can test only one input variable at a level of computation.
Following Ref. [11], a QBP A over the Hilbert space H d is defined as where Ta is a sequence of l instructions, Ta j D x i j ; U j .0/; U j .1/ is determined by the variable x i j tested on step j , and U j .0/, U j .1/ are unitary transformations in H d , d D dim.A/. Vectors j i 2 H d are called states (state vectors) of A, and j 0 i 2 H d is the initial state of A. Quantum branching program as a quantum circuit is shown in Fig. 10. A computation of A on an input D 1 n 2 f0; 1g n is defined as follows.
(1) A computation of A starts from the initial state The j -th instruction of A reads the input symbol i j (the value of x i j ) and applies the transition matrix U j D U j . i j / to the current state j i for obtaining the The final state is Fig. 10 Quantum branching program as a quantum circuit.
BPs and QBPs are convenient computational models in complexity theory. It is easy and natural to define various restricted models for this computational model. The one that we use here is a read-once model, which has the restriction that each input variable can be tested at least once. In this case, we have`D N , meaning that the number of computational steps equal the number of input variables. Note that QQA and QBP in the above forms present a quantum algorithm in terms of linear transformations of quantum states by applying unitary d d matrices U . Such an abstract linear presentation is important for the complexity analysis of a quantum algorithm. However, the programming of the quantum algorithm uses a different kind of presentation.

QQA
One of the tools for constructing the algorithm is to change a quantum register. We present here as an example of important tool for inverting the sign of amplitude that is one of the main steps in Grover's search algorithm.
A w-register can be changed as follows. Let S D fj1i; : : : ; jwig be the basis states. Any jai 2 S is represented as ji; j i, where i denotes variable x i tested in state jai and j corresponds to the j -th x i testing at the level where jai is located. The query Q performs the transformation (inverting the sign of amplitude): Q W ji; j i 7 ! . 1/ x i ji; j i : Inverting the sign of amplitude for a state jii where x i is tested can be implemented using an additional qubit j'i. After the last transformation, the state of the algorithm is measured with regard to j0i; : : : ; jw 1i and the result is transformed into the answer of the algorithm according to a predefined rule.
Two most frequently considered types of quantum query algorithms are exact and bounded error algorithms. In this work, we will consider only bounded error algorithms. A quantum query algorithm A computes f with bounded error, if for every .x 1 ; : : : ; x N /, for which f .x 1 ; : : : ; x N / is defined, the probability that A outputs f .x 1 ; : : : ; x N / as the answer is at least 2=3.

QBP
We change the read-once QBP P to the following QBP A by modifying its register. Basis states S D fj1i ; : : : ; jd ig are equipped with ancillary qubits as follows. State jai 2 S will be modified by adding state jki and qubit j i, where k is the index of variable x 2 X tested in the state jai and j i, and presents a Boolean value of the input x tested. The new basis states are that S 0 will be S 0 D fjki jai j i W k 2 f1; : : : ; N g; a 2 f1; : : : ; d g; 2 f0; 1gg.
From the initial state of jj 1 i j 0 i j0i, where j 0 i is a starting state of Q, the transformation of A moves through the following sequence: Q; U 1 ; Q; T; Q; U 2 ; Q; T; Q; : : : ; Q; U N : The matrix T defines a transition that changes the testing variable's index on the current level to the variable that is tested on the next level: T W jj z i jai j i ! jj zC1 i jai j i : The matrix Q is a query, such that Q W jki jai j i ! jki jai j ˚x k i : U i is an operator from QBP P that is oriented for acting on the basis states of the quantum state. U i applies U 0 i to jai if j i D j0i and applies U 1 i to jai if j i D j1i. We have to apply the query Q twice for one step of the algorithm in order to get state j i D j0i before testing the next input. More precisely, before applying Q, the qubit j i is in the state of j0i. The first application of Q converts jki jai j0i to state jki jai jx k i; the second application of Q converts jki ja 0 i jx k i to jki ja 0 i j0i.

Complexity measures
As the main complexity measures, we use the following: size.A/ is a number of qubits of the underlying quantum register. dim.A/ is the size of the quantum system; that is, the dimension of the quantum states of the register (dim.A/ D 2 size.A/ ). height.A/ is the number of queries for a query model algorithm; height.A/ D N for a quantum branching program. The standard notation for a number of queries in the quantum computation literature for the quantum model is Q.A/ and for the deterministic model is D.A/. time.A/ is a number of basis gates in the quantum circuit that implements A.

Quantum Tools for Quantum Classification
This section presents some quantum subroutines which can be used both independently and as the part of other algorithms. In particular, the controlled normalization operator is used in the algorithm for constructing a superposition of the training set, and the operators for changing the phase of the quantum state by a value that is proportional to the amount of zeroes and for transferring quantum state phase information into the amplitudes subroutine are used in the first quantum k-nearest neighbor algorithm. The number incremenntation operation, OR operation, and overflow check subroutine are used in the second quantum knearest neighbor algorithm.

Controlled normalization operator
This gate [12] is designed to divide one part of the quantum register into two parts, so that the coefficients of the untouched parts remain unchanged and the two new parts have the correct normalized coefficients.
Problem. Given a quantum .n C 2/-register and its quantum state is in the form How to achieve the following quantum state: Solution. Given an n-register and a utility register of two qubits.
To separate the second term of the above state (the first utility qubit state is j1i) into two parts, one where the state of the second utility qubit is j0i with coefficient 1 p p and the other where the state of the second utility qubit is j1i with coefficient s p 2 p ; that is, to achieve the following quantum state: where the first utility qubit ju 1 i acts as a control qubit The following quantum state can be obtained by applying the following controlled gate to the utility register ju 1 i ju 2 i:

Changing the phase
This operator [12] changes the phase of the state of the quantum register by a value that is proportional to the number of zeroes. Problem. Given a state j 0 i D jm 1 ; : : : ; m n i of a quantum n-register, how to change the phase of the state by a value that is proportional to the number of qubits that is equal 0.
Solution. Apply the unitary operator U D e i 2n D m , is a linear combination of where k is the number of zeroes.

Number incrementation operation
Problem. Given an n-bit number a, how to increment this number (a D a C 1). Solution [13] . One utility qubit is initially set to j1i. Let aOE0; : : : ; aOEn 1 be the binary representation of number a. Increment by 1 flips the least significant bit. If it was flipped from 0 to 1, the addition should be stopped; otherwise, proceed to flip the next least significant bit. Repeat in this way until the bit is flipped from 0 to 1. The utility qubit can be viewed as a flag which signals the first time when a bit was flipped from 0 to 1. The utility qubit is j1i as long as it is required to continue flipping bits and becomes to j0i when bits can stop being flipped.
The time cost of the number incrementation operation is measured by the number of elementary gates (NOT, 2CNOT): if n D 1I 10; if n D 2I 2n 2 C n 5; if n 3 (34) Algorithm 1 shows the procedure, where a is an nbits binary number.

OR operation
Problem. Given t bits, how to apply an OR operation to them.
Solution. Algorithm 2 shows the procedure, where v is an n-qubit register. The algorithm requires n 1 utility qubits.

Overflow check
Problem. Given three integers b, t, and n, such that t n, how to know if b is greater than or equal to n t.
Solution. Consider integer k such that 2 k 1 n Algorithm 1 Increment (a, n) jai a F the number is described with n bits: aOE0; : : : ; aOEn 1, where aOEn 1 is the most significant bit. jai jai˝j1i F initial state for i 2 f0; : : : ; n 2g do jai CNOT.a n ; a i /jai jai CNOT.a i ; a n /jai end for jai CNOT.a n ; a n 1 /jai jai NOT.a n /jai NOT.v 2n 1 /jvi return jv 2n 1 i F result is the state of the last qubit 2 k , and let integer l D 2 k n. Condition b n t can then be rewritten as Let a D l C t . Condition b n t is true if the sum b C a overflows. Choose log 2 t as the most significant qubits of the result of this sum and use the previously described OR operation on them to check for overflow. If the result of this operation is 0 then the condition b n t is met.
Algorithm 3 shows the procedure, where b is an n-bit number, and n and t are integers.

Quantum search
This section presents a quantum solutions for search problems that are faster than classical solutions.

Search problem
Given a function f W OEN ! f0; 1g, find the x 2 fL; : : : ; Rg OEN such that f .x/ D 1. The function f is computed by Oracle.

Classical algorithm and complexity
If we consider deterministic algorithms, the only way to find the required x is the brute-force linear search algorithm. If we consider randomized (probabilistic) algorithms, for set f 1 .1/ D fx W f .x/ D 1g, there exist efficient algorithms. Let t D jf 1 .1/j, if one of x 2 OEN is randomly chosen, the probability of getting the right x is t=N . Therefore, in N=t repetitions, we can find x 2 f 1 .1/ with high probability.

Quantum grover algorithm and complexity
Below, we present a basic "maximum/minimum search" problem that explores the Grover search algorithm. These quantum algorithms play essential roles as subroutines in different quantum algorithms for classification problems. Originally, the Grover algorithm was developed for the "single one search" problem [14] .
Single one search problem. Given a function f W OEN ! f0; 1g, find the x 2 fL; : : : ; Rg OEN , such Consider a quantum register j i with N quantum states or log 2 N qubits. The state x 2 OEN is corresponding to solution x. We start from the state of equal amplitudes for all states, then we apply query to Oracle operator Q that inverts the amplitude of O x 2 f 1 .1/; i.e., Q W ji i ! . 1/ f .i / ji i. After that we apply diffusion operator D: : : : : : : : : : 1 0 0 0 0 0 : : : : : : : : : The diffusion operator rotates each amplitude near the mean of all amplitudes. The repetition of query and diffusion operators increase the amplitude of O x 2 f 1 .1/. In 4 p N steps, we will get the maximal amplitude of the solution O x. After measurement, O x will be obtained with high probability. Algorithm 4 shows the procedure.
Property 2 [14] . Grover's search algorithm A has query complexity of height.A/ D O. In a case of multiple solutions for t D jf 1 .1/j > 1, the property below holds.
Property 3 [15,16] . Grover's search algorithm H˝nj i F We obtain equal amplitudes for i 2 f1; : : : ; 4 Property 4 [17] . In a case of unknown number of solutions t , there is a quantum algorithm A 00 with an expected query complexity of hight.

Amplitude amplification
The amplitude amplification algorithm is a generalization of Grover's search algorithm [15] . There are two generalizations: changing the diffusion operator and changing the query operator. For the first generalization, assuming that we have a quantum algorithm with measurement in the end for the single one search or multiple ones search problems. This quantum algorithm can be represented by a unitary matrix A. If the algorithm has the success probability p, then we can replace the diffusion operator by ARA 1 and do 1= p p steps. We then obtain an algorithm that finds a solution with high probability. Property 5 [15] . Assuming that there is a quantum algorithm A for the single one search problem with measurement only in the end and a small success probability p. The amplitude amplification algorithm which extends Grover's search algorithm by replacing D by ARA 1 has a query complexity of height.A/ D O .height.A/ 1 p p / and an error probability of O.p/. A similar result can be obtained for the multiple ones search problem.
For the second generalization, supposing that we have a complex function f with a classical or a quantum algorithm with measurement only in the end, such that its running time is T .N /. We can then implement it in Oracle and the running time of the one's search will be Q.N / T .N /, where Q.N / is the query complexity of the corresponding version of Grover Algorithm 5 shows the procedure.

Amplitude estimation algorithm
If we do not know the number of ones for function f , we can estimate the probability of success via measurement after several iterations; this approach is called amplitude estimation.
Property 6. For any positive integers k and S, the amplitude estimation algorithm [15] outputs Q a .0 Q a 1/ such that j Q a aj 2 k with probability of at least 8 2 when k D 1 and with probability greater than 1 1 2.k 1/ for k 2. This uses exactly S iterations of Grover's algorithm. If a D 0 then Q a D 0 with certainty, and if a D 1 and S is even, then Q a D 1 with certainty. The algorithm is based on Fourier analysis [18] , like the Shor algorithm [19,20] . This approach can also be  [21][22][23] .
As the first and the last step of the algorithm, we apply the quantum Fourier transform operator F S : In the algorithm, we use two quantum registers: the register j i with N quantum states (dlog 2 N e qubits) and the register j i with S quantum states (dlog 2 Se qubits).
Supposing we have an integer i 2 f1; : : : ; S g and any quantum operator U that can be applied to the register j i. Consider the following operator i U that can be applied to the register j ij i: We will use transformation i O for a query and transformation i D for a diffusion. Algorithm 6 shows the procedure.
One of the applications of the amplitude estimation algorithm is the estimation of jf 1 .1/j [15] ; i.e., the number of arguments for a function f that have a 1-result. The idea is to find the probability of Q a and then jf 1 .1/j Q a=N . The traditional approach for amplitude estimation is not reversible. However, sometimes we need reversiblity; for example, applying the amplitude amplification algorithm and getting a result with high probability. A reversible algorithm [24] uses a coherent form of majority voting to obtain a reversible analog for algorithms like amplitude estimation. The property of this algorithm is presented in Property 7.
Property 7. Let A be a unitary operation that maps H˝l og 2 N j i F Initialization of the Grover's search j i F S j i F quantum Fourier transform for i 2 f1; : : : ; S g do return Q a jaj 1 using Q queries. There exists an algorithm, such that for any > 0, there exists an integer k and a state j i that can be produced and obeys kj i j0˝n k ijyik 2 p 2 using a number of queries bounded above by The basic idea of the algorithm is to prepare k copies of the state p ajyiC p 1 jajjy ? i, coherently compute the median via a reversible circuit, and uncompute the k resource states to find the median of the values of y. There is no better classical algorithm than brute force. The time and query complexity of the classical algorithm is O.N /.
Durr and Høyer [25] developed a quantum algorithm based on the Grover search algorithm from Section 4.2.3. The expected query complexity of the algorithm is O.
p N /. Grover max .L; R; f / searches the index of x 2 fL; : : : ; Rg, which is the maximal element. Algorithm 7 shows the procedure. Let Grover .l; r; f / be a quantum subroutine that returns one of x 2 fl; : : : ; rg, such that f .x/ D 1 with equal probability where l; r 2 OEN . If there is no such x, then the subroutine returns 1. This subroutine was discussed in Section 4.2.3. Let h m W OEN ! f0; 1g be the function such that h m .x/ D f .x/ > f .m/, for m 2 OEN .
Durr and Høyer [25] proved that the expected query complexity of the algorithm is O.
p R L/ and the error probability is 0:5 at most. The "minimum" problem can be defined similarly and the algorithm is the same, but with h m .x/ D f .x/ < f .m/.

SWAP-test
The SWAP-test is the known quantum procedure for the equality test of two unknown quantum states j i and j 0 i. The SWAP-test is used in different areas, including quantum cryptography [26,27] and the quantum nearest neighbors algorithm. "Standard" SWAP-test. The SWAP-test procedure is described by the following quantum circuit (see Fig. 11).
Pr swap OEj i D j 0 i is the probability that the SWAPtest has quantum states j i and j 0 i output the result "j i D j 0 i".
Property 8. For any two different states j i and

Distance computing algorithms
Different quantum subroutines can be used for computing the Euclidean distance between two ndimensional vectors. These are used, for example, in the nearest-neighbor algorithm. Below are some assumptions.
(1) The input vectors x 1 ; : : : ; x m and x are d -sparse for some 1 d n.
(2) Quantum oracles are provided in the form Ojiijj ij0i ! jiijj ijx i j i; Fjiijli ! jiijpos.i; l/i; where pos.i; l/ is the position of l-th non-zero element of x i .
(4) Each vector is normalized to 1, for convenience. (5) The running time of the algorithm is dominated by the number of queries made to oracles O and F. 4.4.1 Inner product method Property 9 [24] . Let v 1 ; : : : ; v m 2 C n be d -sparse unit vectors such that max j 2f1;:::;mg; i 2f1;:::;ng jv j;i j r max ; u 2 C n : Then the task of finding max j 2f1;:::;mg jhujv j ij 2 with error of at most " and with success probability at least 1 ı 0 Before presenting the algorithm, we introduce some unitary transformations and subroutines. We combine the results of majority voting for the amplitude estimation and maximum finding algorithms to obtain the following result. We can efficiently prepare the sates that store the inner products for vectors and then apply the algorithm from Property 10.
Property 11. For any fixed " > 0 and any pair of d -sparse unit vectors u 2 C n and v j 2 C n (where j 2 f1; : : : ; mg, r 0;max max i2f1; ;ng u i and r j;max max i 2f1; ;ng v j;i ), a state of the form p Aj ijyi C p 1 jAjj ijy ? i can be efficiently prepared where y encodes jhujv j ij 2 within error " and jAj 8= 2 using a number of queries

Other methods
There is another way to compute the distances between vectors [24] , based on computing Euclidean distances rather than inner products. This alternative method gives approximately the same speed-up.

Implementation of the algorithms
There are a range of quantum Software Development Kits (SDKs) and languages, some of which already contain implementations of the algorithms that we have covered in this paper (see Table 1). Languages and SDKs:  [29] ; Rigetti forest SDK [30] ; Microsoft Q# [31] ; Quipper [32] . Algorithms: Grover's Search (GS)-In some languages, Grover's search is considered as a partial case of amplitude amplification; Amplitude Amplification (AA); Amplitude Estimation (AE); Maximum Search Algorithm (MAX).

Conclusion
This paper presents preliminary knowledge of quantum computing, including qubits, quantum registers, quantum states, basic transformations, quantum circuits, and information extraction. The fundamental quantum tools for quantum classification algorithms are also discussed. Nailya Salikhova is a PhD student in Kazan Federal University. Her current research interests include quantum computing, machine learning, and data stream processing algorithms.
Dingming Wu received the PhD degree in computer science in 2011 from Aalborg University, Denmark. She is an assistant professor with College of Computer Science & Software Engineering, Shenzhen University, China. Her general research area is data management and mining, including data modeling, database design, and query languages, efficient query and update processing, indexing, and mining algorithms.