Have a personal or library account? Click to login
Implementation of Quantum Fourier Transform and Quantum Hashing for Quantum Devices with Arbitrary Qubit Connectivity Graphs Cover

Implementation of Quantum Fourier Transform and Quantum Hashing for Quantum Devices with Arbitrary Qubit Connectivity Graphs

Open Access
|Dec 2025

Full Article

1.
Introduction

The quantum Fourier transform (QFT) [1] is a well-known computational technique used in many quantum algorithms. The technique is used in quantum addition [2], quantum phase estimation (QPE) [1], quantum amplitude estimation (QAE) [3], the algorithm for solving linear systems of equations [4], Shor’s factoring algorithm [5], 1D wave equation [6], Quantum walks [79] with applications to quantum backtracking [10,11] and others.

In this paper, we are interested in the implementation of this technique on quantum devices as a quantum circuit with basic gates. There are different ways to optimize the circuits, such as invoking it in a parallel way [12] or approximate QFT [13]. We are focusing on the minimization of two-qubit quantum gates in such a circuit because they are the most “expensive” to implement. Many types of quantum computers (e.g., quantum devices based on superconductors) do not allow us to apply two-qubit gates to an arbitrary pair of qubits but have a graph that represents such a restriction. Vertices of the graph correspond to qubits, and two-qubit gates can be applied only to qubits corresponding to vertices connected by an edge. We say that such a graph represents the qubit topology for a device. In this paper, we focus on the number of CNOT gates in a quantum circuit for the QFT algorithm with respect to such a graph. Let a CNOT cost of a circuit be the number of CNOT gates in the circuit. The CNOT cost for a linear nearest-neighbor (LNN) architecture (where the graph is just a chain) was explored by Park and Ahn in [14]. They presenteda circuit that has n2 + n – 4 CNOT cost, where n is the number of qubits. It improved the previous results of [1522]. At the same time, as the authors mentioned, their technique cannot be generalized to more complex graphs. Khadieva in [23] suggested a quantum circuit for a more complex architecture that is a cycle with tails (like a “sun” or “two joint suns”). At the same time, the CNOT cost of this circuit is 1.5n2.

Here, we present a general method that allows us to develop a quantum circuit of the QFT algorithm for an arbitrary connected graph that represents a qubit connectivity graph. Our solution is based on a solution for the Travelling salesman problem (TSP) for a modification of the original graph. Here we present a method and an algorithm for constructing a circuit with O(n22n) time complexity, where n is the number of vertices of the original graph and the approximate solution with polynomial time complexity O(n6) and the differential approximation ratio 12{1 \over 2}.

The constructed circuit has the CNOT cost from n2n – 4 to 3n2 – 3n – 10 depending on the complexity of the graph. If the graph has a Hamiltonian path, then it has the minimum possible CNOT cost at most 1.5n2 – 1.5n – 1. In addition, we compare our results with circuits for specific graphs. In the case of LNN, the CNOT cost is 1.5n2 – 1.5n – 1, that is, 1.5 times larger than the result of [14]. The circuits built by our approach are larger by n CNOT gates than the circuit of [23] with the CNOT cost 1.5n2 – 2.5n – 1. For more complex graphs such as 16-qubit and 27-qubit Eagle r3 architectures of IBMQ that is a cycle with tails (like a “sun”) or its modifications, our generic technique gives a CNOT cost a bit larger than the circuit [23] that was especially constructed for these architectures. Our circuits have CNOT cost 342 for the 16-qubit architecture and 1009 for the 27-qubit one; and [23] has CNOT cost 324 and 957, respectively. The difference is about 5%.

Another technique discussed in this paper is quantum fingerprinting, or quantum hashing. This technique is well known, and it allows us to compute a short hash or fingerprint that identifies an original large data with high probability. The nature of the technique and its implementation is similar to the QFT algorithm [23,24].

The probabilistic (randomized) technique was developed by Frievalds [25]. Then, Ambainis and Frievalds [26] developed its quantum counterpart for automata that was improved by Ambainis and Nahimovs in [27,28]. Later, Buhrman et al. in [29] provided an explicit definition of the quantum fingerprinting technique to construct an efficient quantum communication protocol for equality testing. The technique was applied for branching programs by Ablayev, Gainutdinova, Vasiliev, and co-authors [3034]. Later, they developed the concept of cryptographic quantum hashing [3546]. Then, different versions of hashing functions were applied by Ablayev, Vasiliev, Ziiatdinov, Zinnatullin, and other researchers [24, 4750]. The technique was also extended for qudits [51]. This approach was widely used in different areas like stream processing algorithms [52,53], query model algorithms [54,55], online algorithms [5662], branching programs [6365], developing quantum devices [66], automata (discussed earlier, [6771]), and others.

Turaykhanov, Akat’ev, and co-authors implemented the technique in a real quantum device based on photons [72,73]. The alternative implementation for photon-based real quantum devices was developed by Plachta et al. [74] and Zhao et al. [75]. At the same time, the algorithm was embedded in this device. When we discuss the implementation of the algorithm for “universal” quantum devices such as IBMQ quantum computers or similar, it is important to minimize the number of quantum gates with respect to the architecture restrictions of a quantum device, as we discussed for QFT above. The basic implementation part of quantum hashing circuits is a uniformly controlled rotation operator. The CNOT cost of this operator with respect to the qubit connectivity graph was previously discussed in [76,77] for the linear nearest-neighbor (LNN) architecture and in [78] for more complex graphs. At the same time, the presented approaches have issues with the rotation angle precision, which cannot be too small. This issue is discussed in [79,80].

Kālis in his master’s thesis [81] suggested a shallow circuit for quantum fingerprinting for 3 qubits. Later, the approach was developed in detail and presented in a general way for quantum hashing by Ziatdinov, Khadieva, and Yakaryilmaz [82,83]. The approach allows us to reduce the number of CNOT gates exponentially in computational experiments. At the same time, the theoretical exponential superiority of the shallow circuit is not shown [82,83]. By the way, the method is very perspective for current and near-future quantum devices that definitely cannot support a huge number of CNOT gates. The efficient implementation of the shallow circuit for an automaton that recognizes the MODp = {ak : k mod p = 0} language based on the quantum hashing algorithm was proposed by Khadieva, Salehi, and Yakaryilmaz [79] for devices based on the LNN architecture. Later, a similar technique was applied by Khadieva [23] for a more complex architecture that is a cycle with tails (like a “sun” and “two joint suns”) represented by 16-qubit and 27-qubit Eagle r3 IBMQ architectures. Vasiliev [84] discussed a similar method, but for Rz gates instead of Ry gates.

In this paper, we present a general method that allows us to develop a quantum circuit of the quantum hashing algorithm for an arbitrary qubit connectivity graph. It uses the same tools and approaches as the algorithm for constructing the circuit of QFT. Note that the shallow circuit for quantum fingerprinting and the circuit for QFT have similar structures as was discussed by Khadieva [23]. That is why we consider these two topics together and use common methods for both algorithms.

The CNOT cost of the constructed circuit is from 2n – 2 to 6n – 11 depending on the complexity of the graph. The presented cost value is for one implementation step of the quantum hashing algorithm. If we present the complexity of steps of the algorithm, then the constructed circuit has the CNOT cost from (2n – 4) + 2 to (6n – 13) + 2, which depends on the complexity of the graph. When we apply our approach to the LNN architecture, we obtain a circuit with the same CNOT cost as the circuit specially built for the LNN architecture [79]. If we consider 16- and 27-qubit Eagle r3 IBMQ architectures, then we have a similar situation [23].

The structure of this paper is as follows: Section 2 describes the required notations and preliminaries. Graph theory tools are presented in Section 3. Section 4 provides an algorithm for generating a quantum circuit for quantum hashing. The circuit for the quantum Fourier transform is discussed in Section 5. The final Section 6 concludes the paper and contains some open questions.

2.
Preliminaries
2.1.
Graph Theory

Consider an undirected unweighted graph G = (V, E), where V is the set of vertices and E is the set of undirected edges. Let n = |V| be the number of vertices, and m = |E| be the number of edges.

A non-simple path P is a sequence of vertices (vi1, …, vih) that are connected by edges, i.e., (vij, vij+1) ∈ E for all j ∈ {1, …, h – 1}. A path is called a non-simple cycle if vi1 = vih. Note that a non-simple path and a non-simple cycle can contain duplicates. Let the length of the path be the number of edges in the path, len(P) = h – 1.

A path P = (vi1, … vih) is called simple if there are no duplicates among vi1, …, vih. A simple cycle C = (vi1vih) is a non-simple path with only one duplicate vi1 = vih. The distance dist(v, u) is the length of the shortest path between vertices v and u.

Let Neighbors (v) be a list of neighbors for a vertex v, i.e., Neighbors (v) = (ui1, …, uik) such that (v, uij) ∈ E.

Let us consider an undirected weighted graph S = (V′, E′), where V′ is the set of vertices, and E′ is the set of undirected weighted edges. Let w : V′ × V′ → ℝ be a weight function. We assume that w(v, u) = ∞ if (v, u) ∉ E.

For a path P = (vi1, …, vih),the length w(P) is the sum of edge weights in the path, i.e., w(P)=jh1w(vij,vij+1)w(P) = \sum\limits_j^{h - 1} w \left( {{v_{{i_j}}},{v_{{i_{j + 1}}}}} \right).

2.2.
Quantum Circuits

Quantum circuits consist of qubits and gates. A state of a qubit is a column vector from the ℋ2 Hilbert space. It can be represented by a0|0〉 + a1|1〉, where a0, a1 are complex numbers such that |a0|2 + |a1|2 = 1, and |0〉 and |1〉 are unit vectors. Here we use the Dirac notation. A state of n qubits is represented by a column vector from the ℋ2n Hilbert space. It can be represented by i=02n1ai|i{\sum\nolimits_{i = 0}^{{2^n} - 1} a _i}|i\rangle where ai is a complex number such that i=02n1| ai |2=1\sum\nolimits_{i = 0}^{{2^n} - 1} {{{\left| {{a_i}} \right|}^2} = 1} , and |0〉, … |2n – 1〉 are unit vectors. Graphically, on a circuit, qubits are presented as lines.

As basic gates, we consider the following ones: H=12(1111),X=(0110),Ry(ξ)=(cos(ξ/2)sin(ξ/2)sin(ξ/2)cos(ξ/2)),H = {1 \over {\sqrt 2 }}\left( {\matrix{ 1 & 1 \cr 1 & { - 1} \cr } } \right),X = \left( {\matrix{ 0 \hfill & 1 \hfill \cr 1 \hfill & 0 \hfill \cr } } \right),{R_y}(\xi ) = \left( {\matrix{ {cos(\xi /2)} & { - sin(\xi /2)} \cr {sin(\xi /2)} & {cos(\xi /2)} \cr } } \right), Rz(ξ)=(eiξ200eiξ2), CNOT =(1000010000010010).{R_z}(\xi ) = \left( {\matrix{ {{e^{{{i\xi } \over 2}}}} & 0 \cr 0 & {{e^{ - {{i\xi } \over 2}}}} \cr } } \right),{\rm{ }}CNOT{\rm{ }} = \left( {\matrix{ 1 & 0 & 0 & 0 \cr 0 & 1 & 0 & 0 \cr 0 & 0 & 0 & 1 \cr 0 & 0 & 1 & 0 \cr } } \right).

Additionally, we consider five non-basic gates Rd=(100eiπ2d1),CRd=(100001000010000eiπ2d1),CRz(ξ)=(1000010000eiξ20000eiξ2),{R_d} = \left( {\matrix{ 1 & 0 \cr 0 & {{e^{{{i\pi } \over {{2^{d - 1}}}}}}} \cr } } \right),C{R_d} = \left( {\matrix{ 1 & 0 & 0 & 0 \cr 0 & 1 & 0 & 0 \cr 0 & 0 & 1 & 0 \cr 0 & 0 & 0 & {{e^{{{i\pi } \over {{2^{d - 1}}}}}}} \cr } } \right),C{R_z}(\xi ) = \left( {\matrix{ 1 & 0 & 0 & 0 \cr 0 & 1 & 0 & 0 \cr 0 & 0 & {{e^{{{i\xi } \over 2}}}} & 0 \cr 0 & 0 & 0 & {{e^{ - {{i\xi } \over 2}}}} \cr } } \right), SWAP=(1000001001000001),CRy(ξ)=(1000010000cos(ξ/2)sin(ξ/2)00sin(ξ/2)cos(ξ/2)).SWAP = \left( {\matrix{ 1 & 0 & 0 & 0 \cr 0 & 0 & 1 & 0 \cr 0 & 1 & 0 & 0 \cr 0 & 0 & 0 & 1 \cr } } \right),C{R_y}(\xi ) = \left( {\matrix{ 1 & 0 & 0 & 0 \cr 0 & 1 & 0 & 0 \cr 0 & 0 & {cos(\xi /2)} & { - sin(\xi /2)} \cr 0 & 0 & {sin(\xi /2)} & {cos(\xi /2)} \cr } } \right).

The reader can find more information about quantum circuits in [15,85,86]

3.
Tools

Let us consider an undirected unweighted connected graph G = (V, E) such that n = |V| is the number of vertices and m = |E| is the number of edges.

In this section, we consider the problem of searching for the shortest non-simple path in the graph G that visits all vertices at least once. Formally, we want to construct a non-simple path P = (vi1, …, vik) such that

  • the path visits all vertices, i.e., {vi1, …, vik} = V; and

  • the length of the path P is as small as possible.

The problem is close to the Hamiltonian path problem [87], but here we are allowed to visit a vertex several times. That is why any connected graph has the required path.

To solve this problem, we construct a new complete weighted graph S = (V′, E′) such that

  • The set of vertices V′ is the same as the set of vertices V.

  • Each pair of vertices u′, v′ ∈ V′ is connected, and the weight w(u′, v′) is the length of the shortest path between the corresponding vertices u and v from V, i.e., w(u′, v′) = dist(u, v).

We call it the “supergraph.” Let a TSP path (or a Travelling salesman problem path) P′ be the shortest simple path in S that visits all vertices from V′ exactly once [87]. In a similar way, we can define a TSP cycle C′.

For a TSP path P′ = (vi1, …, vin), let α(P′) be the path in G such that α(P)=Pvi1,vi2°P˜vi2,vi3°P˜vi3,vi4°°P˜vin1,vin.\alpha \left( {{P^\prime }} \right) = {P_{{v_{{i_1}}},{v_{{i_2}}}}}^\circ {{\tilde P}_{{v_{{i_2}}},{v_{{i_3}}}}}^\circ {{\tilde P}_{{v_{{i_3}}},{v_{{i_4}}}}}^\circ \cdots ^\circ {{\tilde P}_{{v_{{i_{n - 1}}}},}},{v_{{i_n}}}.

Here Pvi1, vi2 is the shortest path in G between vi1 and vi2; the path P˜vij,vij+1{{\tilde P}_{{v_{{i_j}}},{v_{{i_{j + 1}}}}}} is the shortest path in G between vij and vij+1 excluding the first vertex in the path that is vij; ⚬ is the concatenation operation.

A TSP path for S and the shortest non-simple path in G that visits all vertices at least once has the following connection.

Lemma 1.

The shortest non-simple path P in G that visits all vertices can be obtained by a TSP path P′ for S as P = α(P′).

Proof.

Let P = α(P′). Assume that there is another non-simple path P^{\hat P} that is shorter than P and visits all vertices of G at least once, i.e., len(P^)<len(P)len(\hat P) < len(P). Let (i1, …, in) be the permutation of (1, …, n) that presents the order of visiting vertices by P^{\hat P} for the first time. The length of the simple path P^=(vi1,,vin){{\hat P}^\prime } = \left( {v_{{i_1}}^\prime , \ldots ,v_{{i_n}}^\prime } \right) in S is less than or equal to the length of the non-simple path P^{\hat P} in G, i.e., len(P^)w(P^)len(\hat P) \ge w\left( {{{\hat P}^\prime }} \right). This happens because the weight of an edge in S is the length of the shortest path between the corresponding vertices of G. At the same time, we have no guarantee that P^{\hat P} goes by this shortest path between vertices. Formally, for any index j, the weight of the edge in S between the vertices vijv_{{i_j}}^\prime and vij+1v_{{i_{j + 1}}}^\prime is w(vij,vij+1)ij+1ijw\left( {v_{{i_j}}^\prime ,v_{{i_{j + 1}}}^\prime } \right) \le {i_{j + 1}} - {i_j}. At the same time, p^{{\hat p}^\prime } visits all vertices of S. So, w(P)w(P^)w\left( {{P^\prime }} \right) \le w\left( {{{\hat P}^\prime }} \right) because P′ is a TSP path. Summarizing, len(P)=w(P)w(P^)len(P^)len(P) = w\left( {{P^\prime }} \right) \le w\left( {{{\hat P}^\prime }} \right) \le len(\hat P). It contradicts our assumption len(P)>len(P^)len(P) > len(\hat P).

There is also a similar connection for cycles.

Lemma 2.

The shortest non-simple cycle C in G that visits all vertices can be obtained by a TSP cycle C′ for S as C = α(C′).

Proof.

The proof is the same as for Lemma 1.

We can note the following property:

Lemma 3.

The length of the shortest non-simple path P that visits all vertices in G at least once is such that n – 1 ≤ len(P) ≤ 2n – 2. A similar result is for a cycle C, i.e., nlen(C) ≤ 2n – 2

Proof.

Let us consider a spanning tree of the graph G = (V, E). It is a tree T = (V, E′), where E′ ⊂ E. The path should visit all vertices. So, we can construct a non-simple path P that is the Euler tour [87] of the tree T. The path covers all the vertices of the graph G, but may not be the shortest. Each edge in the tour is visited at most twice (in the up- and down-direction). There are n – 1 edges in the tree. Therefore, the length of the path is at most 2n – 2. For a cycle, we have a similar situation.

Based on this connection, we can suggest an algorithm for searching the shortest non-simple path in the graph G that visits all vertices at least once.

Assume that we have a procedure that finds a TSP path for S that is TSPpath(S). As an algorithm, we can use the Bellman-Held-Karp algorithm [88,89]. The algorithm has O(n22n) time complexity.

Additionally, we have a procedure ShortestPaths(G) that constructs two n × n-matrices W and A by a graph G.

Elements of the matrix W are the lengths of the shortest paths between each pair of vertices in G, i.e., W[v, u] = dist(v, u). We can use W as a weight matrix for S. In other words, w(v′, u′) = W[v, u], where v′, u′ ∈ V′, and v and u are the corresponding vertices from V.

The matrix A represents the shortest paths between the vertices of G. The element A[v, u] is the last vertex before u in the shortest path from v to u. In other words, if t = A[v, u], then Pv, u = Pv, tu. Based on this fact, we can present a procedure GetPath(v, u) that computes Pv, u using the matrix A. The implementation of the procedure is presented in Algorithm 1.

Algorithm 1 Implementation of GetPath(v, u)

tA[v, u]

Pv, u ← (u)

while tv do

  Pv, u ← (t) ⚬ Pv, u

  tA[v, t]

end while

Pv, u ← (v) ⚬ Pv, u

return Pv, u

Let the procedure GetPathNoFirst(v, u) return P˜v,u{{\tilde P}_{v,u}}, that is, the path Pv, u without the first element. The implementation is the same, but without the Pv, u ← (v) ⚬ Pv, u line.

We can construct these two matrices using n invocations of the Breadth First Search (BFS) algorithm [87]. The total time complexity for the construction of the matrices is O(n3). The algorithm for constructing A and W is presented in Appendix D for completeness of presentation.

Due to V′= V, and the matrix W representing the weights of the supergraph’s edges, we can say that ShortestPaths(G) constructs the graph S.

Finally, we can present Algorithm 2 to solve the problem.

Algorithm 2 Implementation Algorithm for searching a shortest non-simple path in the graph G that visits all vertices at least once

W, A ← ShortestPaths(G) ▷W and V define S

(vi1, …, vik) = P′ ← TSPpath(S)

α(P′) ← GetPath(vi1, vi2)

for j ∈ {2, …, k – 1} do

  α(P′) ← α(P′) ⚬ GetPathNoFirst(vij, vij+1)

end for

Note that if we replace the procedure TSPpath(S) by the procedure TSPcycle(S) that finds a TSP cycle, then we find the shortest non-simple cycle in G that visits all vertices at least once. The time complexity of TSPcycle(S) is the same.We can also modify TSPpath(S) such that it finds a path from the fixed starting vertex vstart that is TSPpath(S, vstart).

Theorem 1.

The time complexity of the presented solution for searching the shortest non-simple path, a path with a fixed starting vertex or a cycle that visits all vertices at least once in the graph G = (V, E) is O(n22n), where n = |V|.

Remark 1.

We can solve the same problem using quantum algorithms. For TSPpath(S), TSPpath(S, vstart) and TSPcycle(S), we can use the quantum analogue of Bellman-Held-Karp algorithm presented by Ambainis et al. [90]. For ShortestPaths(S), we can use the quantum version of the BFS algorithm [9193] several times.

The query complexity of the algorithm [90] presented by Ambainis et al. is O* (1.728n), where O* hides logfactors. The algorithm is based on the Grover search algorithm, whose time complexity is more than the query complexity for an additional log factor [94,95]. So, the time complexity is also O* (1.728n). If we want to discuss it more precisely, then we can check [90,96] which claims the query complexity O(n31.728n).

Finally, the complexity of the quantum algorithm for the problem is O* (1.728n). At the same time, for current applications, we need only a classical solution.

3.1.
Heuristic Solution for Searching a Shortest Non-simple Path That Visits All Vertices Problem

In the practical case, when we have more than 20–30 vertices in a graph, the exact algorithm presented before is too slow. In this section, we present a heuristic solution with polynomial-time complexity, and the outcome is close, under certain criteria, to the optimal solution.

Using a path P = (vi1, …, vih), we can construct a sequence of edges ((vi1, vi2), (vi2, vi3), …, (vih–1, vih)). We can say that these are two equivalent representations of the path. We use both in this section.

Note that the supergraph S defined in Section 3 satisfies the following conditions:

  • S is complete and weighted.

  • The weight of an edge from S is at most n because it is the distance between two vertices in the original graph. Formally, w(v′, u′) = dist(v, u) ≤ n, where v′, u′ ∈ V′, and v, uV.

  • S is metric. This means that the edges satisfy the triangle inequality: w(vi,vj)w(vi,vk)+w(vk,vj)w\left( {v_i^\prime ,v_j^\prime } \right) \le w\left( {v_i^\prime ,v_k^\prime } \right) + w\left( {v_k^\prime ,v_j^\prime } \right) for any vi,vj,vkVv_i^\prime ,v_j^\prime ,v_k^\prime \in {V^\prime }.

Now we present a heuristic procedure 2-Opt(S) to find a good solution to the TSP problem. It finds a TSP cycle C. The algorithm for cycles in the case of general weighted metric graphs was presented in [9799]. Here we present modifications for our graph and for searching a path.

We assume that we have two operations for modification of the list of edges that represents a cycle C:

  • Replace(C, (vij, vij+1), (u, v)) that replaces the edge (vij, vij+1) in C by the edge (u, v)

  • Reverse(C, (vij, vij+1), (vik, vik+1)) that reverses all elements of the list between (vij, vij+1) and (vik, vik+1). Both elements (vij, vij+1) and (vik, vik+1) remain in place.

Both operations can be implemented with O(1) time complexity if C is implemented by the two-directional Linked List data structure [87].

Firstly, we initialize the cycle by ((v1, v2), …, (vn–1, vn), (vn, v1)). Then we repeatedly replace two edges of the cycle as long as this yields a shorter cycle. We check all possible pairs. The implementation is presented in Algorithm 3.

In the case of searching for a path, we have two modifications. That is, if a starting vertex vs and a finishing vertex vf are fixed, then we initialize the path by C( (vs,v1),,(vs2,vs1),(vs1,vs+1),,(vf2,vf1), (vf1,vf+1)(vf+1,vf+2),,(vn1,vn) ),(vn,vf) ).\matrix{ {C \leftarrow \left( {\left( {{v_s},{v_1}} \right), \ldots ,\left( {{v_{s - 2}},{v_{s - 1}}} \right),\left( {{v_{s - 1}},{v_{s + 1}}} \right), \ldots ,\left( {{v_{f - 2}},{v_{f - 1}}} \right),} \right.} \cr {\left. {\left. {\left( {{v_{f - 1}},{v_{f + 1}}} \right)\left( {{v_{f + 1}},{v_{f + 2}}} \right), \ldots ,\left( {{v_{n - 1}},{v_n}} \right)} \right),\left( {{v_n},{v_f}} \right)} \right).} \cr }

Without loss of generality, we can assume that s < f. If the starting and finishing vertices are not fixed, then we check all possible vertices from V′ as vs and vf.

Experiments on real-world instances have shown that 2-Opt(S) achieves much better results than Christofide’s algorithm [100]. Generally, the worst case of 2-Opt(S) may lead to exponential complexity. However, direct analysis shows that the complexity of 2-Opt(S) in the case of supergraphs is O(n4) for cycles and for paths with a fixed starting vertex, where n is the number of vertices.

Algorithm 3 Implementation of 2-Opt(S)

C((v1, v2), …, (vn–1, vn), (vn, v1))

stopFlagFalse

while stopFlag = False do

stopFlagTrue

for k ∈ {1, …, n} do

  for j ∈ {k + 1,…, n} do

   if w(vik, vik+1) + w(vij, vij+1) > w(vik, vij) + w(vik+1, vij+1) then

    Reverse(C, (vik, vik+1), (vij, vij+1))

    Replace(C, (vik, vik+1), (vik, vij))

    Replace(C, (vij, vij+1), (vik+1, vij+1))

    stopFlagFalse

    break both For-loops

   end if

  end for

end for

end while

return C

Theorem 2.

The time complexity of 2-Opt(S) for the supergraph S constructed by G is O(n4) in the case of a cycle; in the case of a path with a fixed starting vertex, it is O(n5); and in the case of a path, it is O(n6).

Proof.

Initialization of C takes O(n) time. Since the weights of the edges are bounded above by n, the weight of any Hamiltonian cycle C is bounded above by n2. In each step of “replacing two edges,” the weight of C is reduced by at least 1, which implies that there are O(n2) steps of “replacing two edges.” In each step, there are O(n2) pairs of edges to compare, and the comparison and replacement of edges takes constant time. In summary, the total complexity is O(n4).

In the case of a path with a fixed starting vertex, we also check all finishing vertices. The number of finishing vertices is n. So, the complexity is O(n5) for searching the path.

In the case of a path, we also check all starting vertices. The number of starting vertices is n. So, the complexity is O(n6) for searching the path.

The heuristic algorithm 2-Opt(S) is designed to compute feasible solutions that are as close as possible to the optimal ones with respect to some criterion. We present two paradigms dealing with polynomial approximation. More details can be found in [98,101].

Definition 1.

Let I be an input and 𝒜 be an approximation algorithm. Let lenopt (I) be the length of a path that returns an optimal solution for the given instance I. Let lenw(I) be the worst possible length that a feasible solution returns for I. Let len𝒜 (I) be the length of the approximation algorithm’s solution. Then, for an instance I

  • the standard approximation ratio is ρA(I)=lenA(I)lenopt(I);{{\rm{\rho }}_{\cal A}}(I) = {{le{n_{\cal A}}(I)} \over {le{n_{opt}}(I)}}

  • the differential approximation ratio is δA(I)=| lenw(I)lenA(I) || lenw(I)lenopt(I) |.{\delta _{\cal A}}(I) = {{\left| {le{n_w}(I) - le{n_{\cal A}}(I)} \right|} \over {\left| {le{n_w}(I) - le{n_{opt}}(I)} \right|}}.

Note that if the ratios are close to 1, then the algorithm has better quality.

For the heuristic algorithms for the traveling salesman problem, we have the following results.

Lemma 4 ([9799]).

The differential approximation ratio for the 2-Opt(𝒮) solution of the Traveling salesman problem achieves 12{1 \over 2}, and if the graph is metric, the standard approximation ratio achieves n2\sqrt {{n \over 2}} . Both of the ratios are tight.

4.
Method for Constructing a Circuit for Quantum Hashing

In this section, we present a method that allows us to construct a circuit for the quantum fingerprinting or quantum hashing algorithm for a connected graph G = (V, E) that is the qubit connectivity graph for a device. More information on the quantum fingerprinting (quantum hashing) algorithm can be found in Appendix B. Here we consider a shallow circuit [81,82] for n control qubits. If we do not have restrictions for applying two-qubit gates (when G is a complete graph or a “star” graph), then the circuit is such that we presented in Figure 1. Here we assume that we have qubits q1, …, qn such that q1, …, qn–1 are control ones and qn is the target one.

Figure 1.

Shallow circuit for quantum fingerprinting or quantum hashing algorithm.

Let qi be the logical qubits of the original circuit; the qubits of a physical device are associated with vertices of the graph G, and we call them vi.

The algorithm for constructing a circuit is the following. We also present it in a flowchart in Figure 2.

  • Step 1.

    We find the shortest non-simple path in the graph G that visits all vertices at least once using the algorithm from Section 3. Assume that the path is P = (vi1, …, vik).

  • Step 2.

    The target qubit qn corresponds to the vertex vi2. The control qubits q1, …, qn–1 correspond to other vertices. We assume that we have a set U of control qubits that are already used. Initially, it is empty U ← ∅. Let j be the index of the element in the path P that corresponds to the target qubit. Initially, j ← 2.

  • Step 3.

    We apply controlled rotation with the control vi1 and the target vi2 qubits. Then, we add vi1 to the set U, i.e., UU ∪ {vi1}.

    In the next steps the target qubit travels along the path P.

  • Step 4.

    If vij+1U, then we apply a controlled rotation to the control vij+1 and the target vij qubits. After that, we add vij+1 to the set U, i.e., UU ∪ {vij+1}. If j = k – 1, then we terminate the algorithm. Otherwise, we go to Step 5.

  • Step 5.

    If vij+2vij, then we continue; otherwise, we go to Step 6. We apply the SWAP gate to vij and vij+1. After that, we update jj + 1 because the value of the target qubit moves to vij+1. Then, we go to Step 4.

  • Step 6.

    If vij+2 = vij, then we update jj + 2. Note that here we stay on the same vertex of the graph G. Then, we go to Step 4.

Figure 2.

The flowchart for algorithm constructing a circuit for quantum hashing.

Let us present a procedure ConstructForPath(P) in Algorithm 4 that implements the above idea for a given path P = (vi1, …, vik). We assume that we have cR(u, v) procedure that applies the controlled rotation operator CRy to u as a control qubit and v as a target one. The angle ξr corresponds to the qubit qr associated with the vertex v. Additionally, we have swap(u, v) procedure that applies the swap gate to u and v qubits.

We assume that ShortestNSPath(G) returns a shortest non-simple path in the graph G that visits all vertices at least once. The implementation of this procedure can be found in Algorithm 2 or Algorithm 3. Finally, we can present Algorithm 5 as an implementation of the quantum fingerprinting (quantum hashing) algorithm.

Proof.

Let us look to the shortest path P = (vi1, …, vk) that visits all vertices at least once.

The shallow circuit (Figure 1) is such that we should apply controlled rotation operators with each qubit as the control qubit and a specific qubit as the target.

The algorithm places the target qubit at vi2. Then, we apply the controlled rotation operator with vi1 as the control qubit. After that, we apply the controlled rotation operator with vi3 as the control qubit. Then, we move the target qubit to vi3 using the swap operator and apply the controlled rotation operator with vi4 as the control qubit.

So, if the target qubit is in vij, then we apply the controlled rotation operator with vij+1 as the control qubit and move the target qubit to vij+1 using the swap gate.

We apply the controlled rotation operator with vij+1 as the control qubit only if it is not in the set U and then add it to the set U. This action guarantees us that we apply the controlled rotation with each qubit only once. At the same time, the path visits each vertex at least once. This means that each qubit (vertex) occurs as vij+1 for some j. So, we apply the controlled rotation operator with each qubit exactly once, and there are no other modifications of the target qubit. Therefore, the circuit implements the shallow circuit of the quantum fingerprinting (quantum hashing) algorithm presented in Figure 1. At the same time, we apply the swap or controlled rotation operators only to neighboring qubits.

Algorithm 4 Implementation of ConstructForPath(P) procedure. Algorithm of constructing circuit for quantum hashing or quantum fingerprinting for a path P = (vi1, …, vik)

U ← ∅ ▷Step 2

j ← 2

cR(vi1, vi2) ▷Step 3

UU ∪ {vi1}

while j < k do

  if vij+1U then ▷Step 4

   cR(vij+1, vij)

   UU ∪ {vij+1}

  end if

  if j = k – 1 then

   j ← + j + 1

  else

   if vij+2 = vij then

    jj + 2 ▷Step 6

   else

   swap(vij, vij+1) ▷Step 5

   jj + 1

   end if

  end if

end while

Algorithm 5 Algorithm of constructing circuit for quantum hashing or quantum fingerprinting for a path P = (vi1, …, vik)

P = (vi1, …, vik) ← ShortestNSPath(G) ▷Step 1

ConstructForPath(P)

Let us show the correctness of the algorithm.

Theorem 3.

The quantum circuit produced by Algorithm 5 implements the shallow circuit of quantum hashing from Figure 1.

We can represent the controlled rotation operator cR(u, v) and the corresponding angle ξ as a sequence of R(v, ξ/2), cnot(u, v), R(v, –ξ/2), and cnot(u, v), (see Figure 3). Here R(v, ξ/2) is the Ry(ξ/2) gate applied to the qubit v; cnot(u, v) is the CNOT for u as a control and v as a target.

Figure 3.

Representation of CRy gate using only basic gates

Additionally, the swap(u, v) gate can be represented as a sequence cnot(u, v), cnot(v, u), and cnot(u, v) (see Figure 4).

Figure 4.

Representation of SWAP gate using only basic gates

Two sequential operators CRy and SWAP that are cR(u, v) and swap(u, v) procedures can be represented by a circuit in Figure 5.

Figure 5.

Representation of a pair CRy and SWAP gates using only basic gates

Note that two sequential cnot(u, v) gates are annihilated, as presented in [23,79]. So, we obtain the circuit in Figure 6.

Figure 6.

Reduced representation of a pair CRy and SWAP gates using only basic gates

Let us look at the CNOT cost of these operators, where the CNOT cost is the number of CNOT operators in the representation of a circuit using only basic gates.

We can say that the CNOT cost of cR(u, v) is 2; CNOT cost of swap(u, v) is 3, CNOT cost of two sequential operators cR(u, v) and cnot(u, v) is 3.

Finally, we can discuss the CNOT cost of the constructed circuit.

Theorem 4.

CNOT cost of the circuit generated by Algorithm 5 is 3k – 4b – 5 ≤ 3k – 5, where k is the length of a shortest non-simple path P = (vi1, …, vik) in the graph G that visits all vertices at least once, and b is the number of indices j such that vij = vij+2.

Proof.

If we look at Algorithm 5, then we can see that it is a sequence of one of three options:

  • a pair of CRy and SWAP gates if vjvj+2 and vj+1U.

  • SWAP gate if vjvj+2 and vj+1U.

  • CRy gate if vj = vj+2 and vj+1U.

Note that the option vj = vj+2 and vj+1U is not possible because vj+1U means that the corresponding qubit was already visited. In that case, we can just exclude it from the path because vj = vj+2. At the same time, it contradicts the condition that P is the shortest path.

The CNOT cost for pairs of CRy and SWAP gates is 3; for the SWAP gate, it is 3; for the CRy gate, it is 2.

Let b be the number of steps where we apply pairs of CRy and SWAP gates or the SWAP gate, and let b be the number of steps where we apply CRy (here we do not count the first and the last vertex from the path because they are processed by the different logic). Here a + 2b = k – 3 because (i) if vj = vj+2, then we use only CRy to vj+1 and skip vj+2 (ii) we do not count the target qubit. So, the total number of CNOT gates is 3a + 2b + 4 = 3(a + 2b + 3) – 4b – 5 = 3k – 4b – 5.

Using Lemma 3 we can estimate the CNOT cost of the circuit and present it in the next corollary.

Corollary 1.

CNOT cost of the circuit that is generated using Algorithm 5 is between 2n – 2 and 6n – 11.

Proof.

The circuit has the minimal CNOT cost if each operation required only two CNOT gates, which means no SWAP gates. This happens if we have a “star” graph, where one vertex (a middle vertex) is connected to all other n – 1 vertices. In that case k = 2(n – 1) – 1 = 2n – 3, we start from a non-middle vertex and come to the middle vertex after each other, except the last one. The value b = n – 3 because each non-middle vertex, except the first and last in the path satisfies the required property. So, the CNOT cost according to Theorem 4 is 3(2n – 3) – 4(n – 3) – 5 = 6n – 9 – 4n + 12 – 5 = 2n – 2.

The maximum value is for k = 2n – 1, and the minimum value for b = 0. So, the maximum value for the CNOT cost is 3(2n – 1) – 5 = 6n – 6 – 5 = 6n – 11.

Typically, the quantum fingerprinting (quantum hashing) algorithm is used several times. For example, for hashing a string of symbols, we should apply the algorithm times (see Appendix B for examples). For this reason, we suggest two strategies.

Strategy with a Path

Let a step be a single application of the quantum fingerprinting algorithm. After each step, we reverse the path P. Then, the target qubit travels back. Additionally, we can see that the operator cR(vik-1, vik) is applied at the end of the odd step and at the beginning of the even step. We can apply it once with a double angle. The same situation with cR(vi1, vi2) on the meeting of even and odd steps. Therefore, we have the following CNOT cost for applications of the quantum hashing algorithm.

Theorem 5.

CNOT cost of the circuit to apply the quantum fingerprinting (quantum hashing) algorithm times is at most (3k – 4b – 7) + 2 ≤(3k – 7) + 2, where k is the length of the shortest non-simple path P = (vi1, …, vik) in the graph G that visits all vertices at least once, and b is the number of indices j such that vij = vij+2.

Proof.

The first step costs 3k – 5 due to Theorem 4. Each next step skips the first cR gate because it is “merged” with the last cR from the previous step. So, its CNOT cost is 3k – 7 because cR costs 2. The total cost is 3k – 5 + (3k – 7)( – 1) = (3k – 7) + 2.

Similarly to Corollary 1 we can show the next result.

Corollary 2.

The CNOT cost of the circuit for application of the quantum fingerprinting (quantum hashing) algorithm times is between (2n – 4) + 2 and (6n – 13) + 2.

Strategy with a Cycle

At the beginning of each step, starting from the second one, we add swap(vik, vi1) and swap(vi1, vi2) gates. We need the first swap because we should start from the beginning of the cycle next time. We add the second one because we should start from the second element of the cycle. These two gates increase the cost by 2 because they are jointed with corresponding cR gates. At the same time, all the logical qubits are moved to position 1 of the cycle. That is why we need only k – 1 travels by the cycle for doing k steps.

Therefore, we have the following CNOT cost for applications of the quantum hashing algorithm.

Theorem 6.

CNOT cost of the circuit for application of the quantum fingerprinting (quantum hashing) algorithm times is at most 3(k1)(+1)(4b+3)(k)+53(k1)(+1)3(k)+53(k - 1)(\ell + 1) - (4b + 3)\left( {\ell - {\ell \over k}} \right) + 5 \le 3(k - 1)(\ell + 1) - 3\left( {\ell - {\ell \over k}} \right) + 5, where k + 1 is the length of the shortest non-simple cycle C = (vi1, …, vik, vi1) in the graph G that visits all vertices at least once, and b is the number of indices j such that vij = vij+2.

Proof.

The first step costs 3k – 4b – 5 due to Theorem 4. Each next step costs 3k – 4b – 3 because of two additional swap gates. At the same time, we should apply them only k \ell - \left\lfloor {{\ell \over k}} \right\rfloor due to the movement of the logic qubits by the cycle.

The total cost is 3k4b5+(3k4b3)( k 1)=(3k4b3)( k )+2=3k4b33k k +(4b+3) k +23k4b33k(k1)+(4b+3)k+2=3k4b33+3k+4bk+3k+2=3k3+3k4b(k)3(k)+2=3k3+3k(4b+3)( k )+2=3k(+1)3(+1)+3(4b+3)(k)+2=3(k1)(+1)(4b+3)(k)+5\matrix{ {3k - 4b - 5 + (3k - 4b - 3)\left( {\ell - \left\lfloor {{\ell \over k}} \right\rfloor - 1} \right) = (3k - 4b - 3)\left( {\ell - \left\lfloor {{\ell \over k}} \right\rfloor } \right) + 2 = } \hfill \cr {3k\ell - 4b\ell - 3\ell - 3k\left\lfloor {{\ell \over k}} \right\rfloor + (4b + 3)\left\lfloor {{\ell \over k}} \right\rfloor + 2 \le 3k\ell - 4b\ell - 3\ell - 3k\left( {{\ell \over k} - 1} \right) + (4b + 3){\ell \over k} + 2 = 3k\ell - 4b\ell - } \hfill \cr {3\ell - 3\ell + 3k + 4b{\ell \over k} + 3{\ell \over k} + 2 = 3k\ell - 3\ell + 3k - 4b\left( {\ell - {\ell \over k}} \right) - 3\left( {\ell - {\ell \over k}} \right) + 2 = 3k\ell - 3\ell + 3k - (4b + 3)(\ell - } \hfill \cr {\left. {{\ell \over k}} \right) + 2 = 3k(\ell + 1) - 3(\ell + 1) + 3 - (4b + 3)\left( {\ell - {\ell \over k}} \right) + 2 = 3(k - 1)(\ell + 1) - (4b + 3)\left( {\ell - {\ell \over k}} \right) + 5.} \hfill \cr } .

Due to b ≥ 0, we have 3(k1)(+1)(4b+3)(k)+53(k1)(+1)3(k)+53(k - 1)(\ell + 1) - (4b + 3)\left( {\ell - {\ell \over k}} \right) + 5 \le 3(k - 1)(\ell + 1) - 3\left( {\ell - {\ell \over k}} \right) + 5.

Similarly to Corollary 1 we can show the next result.

Corollary 3.

The CNOT cost of the circuit for application of the quantum hashing (quantum fingerprinting) algorithm ℓ times is between (2n4)+22n12(2n - 4)\ell + 2\ell - {{2\ell } \over {n - 1}} - 2 and (6n13)++6n+62n111(6n - 13)\ell + \ell + 6n + {{6\ell } \over {2n - 1}} - 11.

Proof.

Let us estimate the minimal cost similarly to Corollary 1. The first step costs 2n – 2. Each next step costs 2n – 2 + 2 = 2n. The total complexity is 2n2+2n( k 1)=2n( k )22n(k)22n(n1)2=2n(2n2+2)n12=2n2(n1)n12n12=2n22n12=(2n4)+22n12\matrix{ {2n - 2 + 2n\left( {\ell - \left\lfloor {{\ell \over k}} \right\rfloor - 1} \right) = 2n\left( {\ell - \left\lfloor {{\ell \over k}} \right\rfloor } \right) - 2 \ge 2n\left( {\ell - {\ell \over k}} \right) - 2 \ge } \hfill \cr {2n\left( {\ell - {\ell \over {n - 1}}} \right) - 2 = 2n\ell - {{(2n - 2 + 2)\ell } \over {n - 1}} - 2 = 2n\ell - {{2(n - 1)\ell } \over {n - 1}} - {{2\ell } \over {n - 1}} - 2 = 2n\ell - 2\ell - {{2\ell } \over {n - 1}} - 2 = (2n - 4)\ell + 2\ell - {{2\ell } \over {n - 1}} - 2} \hfill \cr } .

Let us estimate the maximal cost similarly to Corollary 1. The first step costs 6n – 11. Each next step costs 6n – 11 + 2 = 6n – 9. The total complexity is 6n11+(6n9)( k 1)=(6n9)( k )2(6n9)( 2n1 )2(6n9)(2n1+1)2=(6n9)+(6n9)3(2n12)2n12=(6n9)+(6n9)3+62n12=(6n13)++6n+62n1116n - 11 + (6n - 9)\left( {\ell - \left\lfloor {{\ell \over k}} \right\rfloor - 1} \right) = (6n - 9)\left( {\ell - \left\lfloor {{\ell \over k}} \right\rfloor } \right) - 2 \le (6n - 9)\left( {\ell - \left\lfloor {{\ell \over {2n - 1}}} \right\rfloor } \right) - 2 \le (6n - 9)\left( {\ell - {\ell \over {2n - 1}} + 1} \right) - 2 = (6n - 9)\ell + (6n - 9) - 3{{(2n - 1 - 2)\ell } \over {2n - 1}} - 2 = (6n - 9)\ell + (6n - 9) - 3\ell + 6{\ell \over {2n - 1}} - 2 = (6n - 13)\ell + \ell + 6n + {{6\ell } \over {2n - 1}} - 11.

We can see that the complexity presented in Corollary 1 is less than the result from Corollary 3 because each cycle that visits all the vertices at least once can be converted to a path by removing the last edge. At the same time, the repeated application of the same pattern of gates for each step can be useful in some hardware implementations.

4.1.
Comparing with Existing Results

Let us compare our generic approach with existing circuits for specific graphs. The LNN architecture is a common layout graph for many quantum devices. The graph is a chain where v1 is connected with v2; vi is connected with vi–1 and vi+1 for i ∈ {2, …, n – 1}; vn is connected with vn–1.

The quantum fingerprinting (quantum hashing) algorithm for the LNN architecture was discussed in [79]. The path that visits all vertices in the graph is simply P = (v1, …, vn) (see Figure 7). So, our method gives us the same circuit as in [79]. The circuit for the quantum fingerprinting algorithm on 5 qubits is presented in Figure 8.

Figure 7.

The graph for the 5-qubit LNN architecture. The path that visits all vertices at least once is green.

Figure 8.

A quantum circuit for the Quantum hashing (quantum fingerprinting) algorithm for 5 qubits LNN architecture device.

The CNOT cost of the circuit is presented in the next lemma.

Lemma 5.

The CNOT cost of the produced circuit of the quantum fingerprinting (quantum hashing) algorithm with n qubits for the LNN architecture is 3n – 5 for one application and 3nℓ – 7 + 2 for applications.

Let us consider more complex graphs like a cycle with tails (like a “sun” or “two joint suns”). The 16- and 27-qubit IBM machines of this architecture were considered in [23]. The graphs and paths are presented in Figures 9 and 10.

Figure 9.

The graph for 16-qubit “sun” architecture. The path that visits all vertices at least once is green. Red parts are such that vij = vij+2.

Figure 10.

The graph for 27-qubit “two joint suns” architecture. The path that visits all vertices at least once is green. Red parts are such that vij = vij+2.

Note that the red part of the path is such that vj+2 = vj. Therefore, we do not apply a SWAP gate on this part of the path, but only a CRy gate. So, our generic method gives the same circuits as the circuits specially constructed for these devices [23]. The CNOT cost is 40 for the 16-qubit architecture, and 69 for the 27-qubit one.

We collect the results for the discussed architectures in Table 1 for LNN and Table 2 for others. Additionally, we added results in Table 3 for connectivity graphs of IBMQ Melbourne, Rigetti Aspen-4, and a 5 × 5-grid as a connectivity graph that can be found, for example, in [102]. They are presented in Figure 11.

Figure 11.

Connectivity graphs of IBMQ Melbourne, Regetti Aspen-4, and 5 × 5-grid.

Table 1.

The CNOT cost for the LNN architecture. The CNOT cost of circuits produced by algorithms from [79] and this paper is 3n – 5

The number of qubits n[79] and this paperQiskit transpiler
51014
102539
Table 2.

The CNOT cost for “sun” and “two joint suns” architectures

Connectivity graph’s type[23] and this paperQiskit transpiler
16-qubit “sun” architecture4057
27-qubit “two joint suns” architecture69115
Table 3.

The CNOT cost for IBMQ Melbourne, Regetti Aspen-4, and 5 × 5-grid

Connectivity graph’s typeThis paperQiskit transpiler
14-qubit IBMQ Melbourne3644
16-qubit Regetti Aspen-44366
25-qubit 5 × 5-grid7084

Moreover, we compare our algorithm with Qiskit transpiler [103] optimized circuit for the mentioned architectures. The Qiskit’s algorithm is randomized heuristic algorithm for circuit optimization. That is why we invoke it 100 times and choose the minimum of the produced circuits’ CNOT costs. We added the results to the tables.

The results were obtained using the algorithm implemented in C++. The implementation can be found in GitLab repository [104].

Remark 2.

In this paper, we focus on the CNOT cost (the number of CNOT gates) because two-qubit gates are harder to implement on real devices and give larger computational error compared to one-qubit gates. At the same time, there is another common metric of circuit quality that is depth (the number of steps, where each step is a layer of gates that can be done in parallel on different qubits). Often, the depth of a circuit is associated with time complexity. We do not optimize this metric in this paper. However, if we compute the depth of the circuit, then it can be obtained from the CNOT cost by adding 2(n – 1) because we do n – 1 controlled rotations in total and each of them requires two rotation gates as shown in Figure 3.

5.
Method for Constructing a Circuit for Quantum Fourier Transform

Here we present a method that allows us to construct a circuit for the Quantum Fourier Transform (QFT) for a connected graph G = (V, E) that is a qubit connectivity graph for a device. More information about the QFT algorithm can be found in Appendix C. If we do not have restrictions for applying two-qubit gates (when G is a complete graph for instance), then the circuit is as presented in Figure 12.

Figure 12.

A quantum circuit for the Quantum Fourier Transform algorithm for fully connected 5 qubits.

The author of [23] shows that the circuit for QFT is a series of CNOT cascades. Each of the cascades has a gate structure similar to the shallow circuit for the quantum hashing algorithm. Assume that we have a ConstructQFTForPath(P′, k′, r) procedure that constructs the r-th cascade of the circuit for QFT for a path P′of length k′. Note that for QFT, the size of each cascade is different. Here P′ is a path that visits only the vertices corresponding to the qubits used in the current cascade. Firstly, we present the main algorithm in Section 5.1. Then we present an algorithm for the ConstructQFTForPath(P′, k′, r) procedure in Section 5.2. After that we discuss the complexity of the circuit in Section 5.3. Finally, we compare the circuit with existing results in Section 5.4.

5.1.
The Main Algorithm

Let us present the whole algorithm for constructing the quantum circuit for the QFT algorithm.

Firstly, we find a non-simple path P = (vi1, …, vjk) that visits all vertices at least once. Then we assign logical qubits to the vertices according to this path. Let indices j1, …, jn be the indices of the first occurrence of each vertex. In other words, jr is such that ijr = r, and ihr for each 1 ≤ h < jr.

Then, we assign Qrjr the position of r-th logical qubit in the graph, and Tjrr the index of the logical qubit associated with a vertex.

After that, we start to construct the circuit for cascades. For the first cascade, we invoke ConstructQFTForPath(P, k). Similarly to the quantum hashing (quantum fingerprinting) algorithm, the target qubit (i.e., 1st logical qubit) moves to the end of the path, i.e., Q1 = ik.

For the second cascade, we exclude the vertex with index Q1 from the graph and find the path P′ that visits all vertices at least once in the updated graph such that it starts from the vertex vQ2. The vertex vQ2 contains the 2nd logical qubit that should be the target in the second cascade. Then, we invoke ConstructQFTForPath(P′, k′), where k′ is the length of P′.

For the next cascades, we act in a similar way. For the r-th cascade, we exclude vQr–1, find the path P′ that visits all vertices at least once in the updated graph such that it starts from the vertex vQr, and invoke ConstructQFTForPath(P′, k′).

Note that a path in the updated graph always exists because it is connected. We have at least one path that visits all vertices at least once, and we exclude only one vertex, that is, the last one on this path.

During the implementation, we do not remove the vertex from the graph; we just store a set of “deleted” vertices and we prohibit visiting vertices from this set during the algorithm for the path search.

Let us present the algorithm.

  • Step 1.

    We find a non-simple path P = (vi1, …, vik) that visits all vertices at least once.

  • Step 2.

    We find indices j1, …, jn, where jr is such that ihijr for each 1 ≤ h < jr. Then, we assign Qrjr and Tijrr for 1 ≤ rn.

  • Step 3.

    We assign P′ ← P, and k′ is the length of P′. We assign r ← 1, which is an index of the cascade.

The next steps are repeated while the graph contains at least one vertex.

  • Step 4.

    We find a non-simple path P′ of length k′ that visits all non-deleted vertices of the graph and starts from vQr. If r = 1, then we do nothing because P′ was already found in Steps 1-3.

  • Step 5.

    We invoke ConstructQFTForPath(P′, k′, r), which is the r-th cascade. Assume that the procedure keeps the Q and T indices actual.

  • Step 6.

    We exclude vQr from the graph.

  • Step 7.

    If r = n, then we terminate the algorithm. Otherwise, we increase the index of the cascade rr + 1 and go to Step 4.

The implementation of the algorithm is presented in Algorithm 6. Assume that we have the ShortestNSPath(G) procedure that returns the shortest non-simple path visiting all vertices, and the ShortestNSPath(G, v) procedure that returns a similar path that starts from the vertex v. Let getFirstIndices(P) be a procedure that returns j1, …, jn. The implementation of this procedure is simple, has O(k log n) time complexity, and is presented in Appendix D.

Algorithm 6 Implementation of the algorithm for constructing the whole circuit for QFT for a path P = (vi1, …, vik)

P ← ShortestNSPath(G), klen(P)

(j1, …, jn) ← getFirstIndices(P)

for r ∈ {1, …, n} do

  Qrjr

  Tijrr

end for

P′ ← P, k′ ← k, r ← 1

while rn do

  ConstructQFTForPath(P′, k′, r)

  VV\{vQr}

  rr + 1

  if rn then

    P′ ← ShortestNSPath(G, vQr), k′ ← len(P′)

  end if

end while

Let us discuss the time complexity of the algorithm. The time complexity of ShortestNSPath(G) and ShortestNSPath(G, v) is O(n22n) due to Theorem 1. In each step, the number of vertices is reduced by 1. So, the total complexity is O(i=1n(i22i))=O(n22n)O\left( {\sum\limits_{i = 1}^n {\left( {{i^2}{2^i}} \right)} } \right) = O\left( {{n^2}{2^n}} \right). In the case of the heuristic solution, we have a similar situation. The complexity of the presented solution from Section 3.1 is O(i=1ni5)=O(n6)O\left( {\sum\limits_{i = 1}^n {{i^5}} } \right) = O\left( {{n^6}} \right).

5.2.
Quantum Circuit for One Cascade

The procedure ConstructQFTForPath(P′, k′, r) is very similar to the ConstructForPath(P) procedure that constructs the circuit for the quantum hashing algorithm. At the same time, there are many small, specific modifications. That is why we present the whole algorithm here.

  • Step 1.

    We start with the first qubit in the path j ← 1. We apply the Hadamard transformation to the qubit corresponding to the vertex vi1. We denote this action by H(vi1). If k′ = 1, then we terminate our algorithm; otherwise, go to Step 2.

  • Step 2.

    If j = k′, then we terminate the algorithm; otherwise, we continue. If vij+1U, then we apply the controlled phase gate CRd with the control vij+1 and the target vij. qubits, where d = Tij+1r. Then, we add vij+1 to the set U, i.e., UU ∪ {vij+1 }. Then, we go to Step 3.

  • Step 3.

    If j = k′ – 1 or vij+2vij, then we continue; otherwise, we go to Step 4. We apply the SWAP gate to vij and vij+1, and swap the indices of qubits for these vertices. In other words, if w1 = Tij and w2 = Tij+1 are indices of the corresponding logical qubits, then we swap Qw1 and Qw2 values, and Tij and Tij+1 values. Then, we update jj + 1 because the value of the target qubit moves to vij+1. Then, we go to Step 2.

  • Step 4.

    If vij+2 = vij, then we update jj + 2. Note that here we stay on the same vertex of the graph G. Then, we go to Step 2.

Finally, we obtain ConstructQFTForPath(P′, r) procedure whose implementation is presented in Algorithm 7. This procedure constructs the r-th part (cascade) of the circuit for QFT for the path P′.

Algorithm 7 Implementation of ConstructQFTForPath(P′, k′, r) procedure. Algorithm of constructing the circuit for the r-th cascade for the path P′ = (vi1, …, vik′)

j ← 1 ▷Step 1

H(vij)

U ← ∅

while jkdo ▷Step 2

  if vij+1U then

    dTij+1r

    CRd(vij+1, vij)

    UU ∪{vij+1}

  end if

  if j = k′ or vij+2vij. then ▷Step 3

    if k′ = 2 then

      swap(vij, vij+1)

      w1Tij, w2Tij+1

      Qw1ij+1, Qw2ij

      Tijw2, Tij+1w1

    end if

    jj + 1

  else ▷Step 4

    jj + 2

  end if

end while

5.3.
The CNOT Cost of the Circuit and Correctness of the Algorithm

Let us start with discussion correctness of the algorithm.

Theorem 7.

The quantum circuit produced by Algorithm 6 implements the circuit of the quantum Fourier transform algorithm from Figure 12.

Proof.

The r-th cascade of the QFT circuit is such that we should apply controlled phase operators with each logical qubit with indexes larger than r as the control qubit and r-th qubit as the target.

For the cascade, the algorithm computes the path that starts from the vertex corresponding to the r-th logical qubit and visits all vertices corresponding to the logical qubit with indexes larger than r. Let the path be P=(vi1,,vik){P^\prime } = \left( {{v_{{i_1}}}, \ldots ,{v_{i_k^\prime }}} \right). Here we use the qubit from vi1 as a target qubit. It corresponds to the r-th logical qubit. Then, we apply the controlled phase operator with vi2 as the control qubit. After that, we move the target qubit to vi2 using the swap operator and apply the controlled phase operator with vi3 as the control qubit.

So, if the target qubit is in vij, then we apply the controlled phase operator with vij+1 as the control qubit and move the target qubit to vij+1 using the swap gate.

We apply the controlled rotation phase with vij+1 as the control qubit only if it is not in the set U, and then add it to the set U. This action guarantees us that we apply the controlled phase operator with each required qubit only once. At the same time, the path visits each vertex corresponding to logical qubits with indexes larger than r at least once. This means that each qubit (vertex) occurs as vij+1 for some j. So, we apply the controlled phase operator with each qubit exactly once, and there are no other modifications of the target qubit. Therefore, the circuit implements the r-th cascade.

After that we exclude the vertex corresponding to r-th logical qubit from the graph. Note that the rest of the graph is connected because the r-th logical qubit moved to the end of the path P′. So, we can be sure that all vertices corresponding to logical qubits with indexes larger than r are connected with path P′ without the last vertex. Therefore, we can repeat the algorithm for the next cascades.

So, the produced circuit implements all cascades of the QFT circuit presented in Figure 1. At the same time, we apply the swap or controlled phase operators only to neighboring qubits.

Let us continue with CNOT cost of the circuit.

Note that the CRd gate can be represented using only two CNOT gates and three Rz gates similar to CRy [105] (see Figure 13).

Figure 13.

Representation of CRd gate using only basic gates.

A pair CRd and SWAP can be represented using three CNOT gates. (See Figure 14).

Figure 14.

Reduced representation of a pair Rd and SWAP gates using only basic gates.

Theorem 8.

If the graph G with n vertices has a Hamiltonian path, then the CNOT cost of the produced circuit for the QFT algorithm is 1.5n2 – 1.5n – 1.

Proof.

Because the graph has a Hamiltonian path, the path P = (vi1, …, vin) is exactly this path. So, in each step, we move the target qubit. We can say that in constructing the r-th cascade, we use the path P′ = (vi1, …, vinr+1). The CNOT cost of the r-th cascade for 1 ≤ rn – 2 is 3(nr) because we apply SWAP and the controlled phase gates for each edge of the path. The CNOT cost of the (n – 1)-th cascade is 2 because we do not apply the SWAP gate. The CNOT cost of the n-th cascade is 0. Therefore, the total cost is r=1n1(3(nr))1=1.5n21.5n1\sum\limits_{r = 1}^{n - 1} {(3(} n - r)) - 1 = 1.5{n^2} - 1.5n - 1.

Let us discuss the CNOT cost of the algorithm in the next theorem.

Theorem 9.

The CNOT cost of a circuit that is generated using Algorithm 5 is between n2+ n – 4 and 3n2 – 3n – 10.

Proof.

Similarly to Corollary 1, the minimal possible cost is when we move the target qubit the minimum possible times. It is the situation with the “star” graph where we have a vertex connected with all others. The cost of the r-th cascade in that case is 3 + 3 + 2 · (n – 2 – r) = 2(nr) + 2, because we always remove one “non-middle” vertex. The path starts from “non-middle” and finishes in “non-middle.” Therefore, we should make two moves of the target qubit. For the (n – 1)-th cascade, the cost is only 2. So, the total complexity is at least r=1n2(2(nr)+2)+2=n2+n4\sum\limits_{r = 1}^{n - 2} {(2(} n - r) + 2) + 2 = {n^2} + n - 4.

Similarly to the proof of Theorem 4, we can show that the CNOT cost of one cascade is at most 3(k – 1). After each cascade, the number of vertices is decreased by 1. The maximum possible value for k is 2n – 1. In the r-cascade, it is 2(nr + 1) – 1 = 2(nr) + 1. The cost of the (n – 1)-th cascade is 2, not 3, because we do not move the target qubit. The cost of the (n – 2)-th cascade is 6, because the length of the path in the graph with 3 vertices is always 3. So, the total complexity is at most r=1n3(3·2(nr))+6+2=3n23n10\sum\limits_{r = 1}^{n - 3} {(3\;\cdot\;2(n - r))} + 6 + 2 = 3{n^2} - 3n - 10.

5.4.
Comparing with Other Results

Similarly to Section 4.1 we discuss the LNN architecture and the more complex architecture. Firstly, let us consider the LNN architecture. As discussed earlier (see Figure 7), the path visits all vertices from v1 to vn one by one. The paths constructed for each cascade are presented in Appendix E. The circuit is similar to the circuit developed in [23]. The presented path is the Hamiltonian path in the graph. Due to Theorem 8, we get the following CNOT cost for the LNN architecture.

Lemma 6.

The CNOT cost of the produced circuit of the QFT algorithm using n qubits for the LNN architecture is 1.5n2– 1.5n – 1.

At the same time, [14] gives the circuit with n2 + n – 4 CNOT cost, and [23] gives the circuit with 1.5n2 – 2.5n + 1 CNOT cost. Our circuit is better than [14] only if n ≤ 3. The result from [23] is better than our result. However, it is not known how to apply the results of [14] for more complex architectures, and the results of [23] are presented only for a specific architecture.

Secondly, let us consider more complex architectures like 16-qubit “sun” (Figure 9), and 27-qubit “two joint suns” (Figure 10). The paths are presented in figures. Note that the red part of the path is such that vj+2 = vj. Therefore, we do not apply a SWAP gate on this step, but only the controlled phase operator. The CNOT cost for the 16-qubit machine is 342, and for the 27-qubit machine is 1009.

So, our generic method gives circuits that are a bit worse than the circuits constructed especially for these devices [23], which CNOT costs are 324 and 957 for the 16-qubit and the 27-qubit architectures, respectively. The difference is about 5%.

We have collected the results of discussed architectures in Table 4 for LNN and Table 5 for others. Additionally, we added results in Table 6 for connectivity graphs of IBMQ Melbourne, Rigetti Aspen-4, and a 5 × 5-grid as a connectivity graph that can be found, for example, in [102]. They are presented in Figure 11.

Table 4.

The CNOT cost of quantum circuit for the QFT algorithm for LNN architecture. The CNOT cost of circuits produced by the algorithm from [14] is n2 + n – 4; by the algorithm from [79] is 1.5n2 – 2.5n + 1; the algorithm from this paper is 1.5n2 – 1.5n – 1.

The number of qubits nThis paper[14][79]Qiskit transpiler
38879
417161521
529262638
10134106126207
Table 5.

The CNOT cost of quantum circuit for the QFT algorithm for “sun” and “two joint suns” architectures

Connectivity graph’s typeThis paper[23]Qiskit transpiler
16-qubit “sun” architecture342324549
27-qubit “two joint suns” architecture10099571839
Table 6.

The CNOT cost of quantum circuit for the QFT algorithm for IBMQ Melbourne, Regetti Aspen-4, and 5 × 5-grid

Connectivity graph’s typeThis paperQiskit transpiler
14-qubit IBMQ Melbourne269335
16-qubit Regetti Aspen-4359585
25-qubit 5 × 5-grid8991158

Moreover, we compare our algorithm with the Qiskit transpiler [103] optimized circuit for the mentioned architectures. The Qiskit’s algorithm is a randomized heuristic algorithm for circuit optimization. That is why we invoke it 100 times and choose the minimum of the produced circuits’ CNOT costs. We added the results to the tables.

The results were obtained using the algorithm implemented in C++. The implementation can be found in the GitLab repository [104].

Remark 3.

As we discussed in Remark 2, here, we focus on the CNOT cost but not the depth of the circuit. If we compute the depth of the circuit, then it can be obtained from the CNOT cost by adding n2 because for r-th cascade we do nr controlled phase gates in total and each of them required two additional layers for rotation gates as shown in Figure 13. Moreover, we add one H gate. So, the depth of the r-th cascade is 2(nr) + 1. The total depth is c+r=1n(2(nr)+1)=c+n2c + \sum\limits_{r = 1}^n {(2(} n - r) + 1) = c + {n^2}, where c is the CNOT cost of the produced circuit.

6.
Conclusion

We present a generic method for constructing quantum circuits for quantum fingerprinting (quantum hashing) and quantum Fourier transform algorithms for an arbitrary connected qubit connectivity graph for hardware. The heuristic version of the method is fast enough and works with O(n6) time complexity. The certain version has an exponential time complexity that is O(n22n). The algorithm works for an arbitrary qubit connectivity graph.

At the same time, if we consider samples of graphs like LNN, “sun” (16-qubit IBMQ Eagle r3 architecture), “two joint suns” (27-qubit IBMQ Eagle r3 architecture), then our generic algorithm gives us the same circuit as the techniques provided especially for these graphs [23,79] in the case of quantum hashing. In the case of QFT, our algorithm gives a bit worse circuit compared to the techniques optimized for these graphs [14,23]. At the same time, our approach works for arbitrary connected graphs, but the existing results work only for some specific graphs. Additionally, we consider other different architectures like IBMQ Melbourne, Rigetti Aspen-4, and a 5 × 5-grid as a connectivity graph. We show that for all of the considered connectivity graphs, including LNN, “sun,” and “two joint suns,” our algorithm produces circuit better than standard Qiskit transpiler optimization.

An open question is to develop a technique for QFT for an arbitrary connected graph that gives us the same or better results than the existing ones for specific architectures like LNN, “sun” and “two joint suns.”

DOI: https://doi.org/10.2478/qic-2025-0028 | Journal eISSN: 3106-0544 | Journal ISSN: 1533-7146
Language: English
Page range: 509 - 541
Submitted on: May 28, 2025
|
Accepted on: Sep 2, 2025
|
Published on: Dec 31, 2025
In partnership with: Paradigm Publishing Services
Publication frequency: 1 issue per year

© 2025 Kamil Khadiev, Aliya Khadieva, Zeyu Chen, Junde Wu, published by Cerebration Science Publishing Co., Limited
This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 License.