Comparison among Classical, Probabilistic and Quantum Algorithms for Hamiltonian Cycle problem

The Hamiltonian cycle problem (HCP), which is an NP-complete problem, consists of having a graph G with n nodes and m edges and finding the path that connects each node exactly once. In this paper we compare some algorithms to solve a Hamiltonian cycle problem, using different models of computations and especially the probabilistic and quantum ones. Starting from the classical probabilistic approach of random walks, we take a step to the quantum direction by involving an ad hoc designed Quantum Turing Machine (QTM), which can be a useful conceptual project tool for quantum algorithms. Introducing several constraints to the graphs, our analysis leads to not-exponential speedup improvements to the best-known algorithms. In particular, the results are based on bounded degree graphs (graphs with nodes having a maximum number of edges) and graphs with the right limited number of nodes and edges to allow them to outperform the other algorithms.


Introduction
A Hamiltonian cycle is a cycle in an undirected or directed graph that visits each vertex exactly once.Hamiltonian Cycle problem (HCP) is the problem to determine if a Hamiltonian cycle exists in a given graph.
HCP is in NP, and precisely it is NP-complete.Shortly, the first proposition indicates that while it is almost impossible to find an efficient solution for HCP, it is straight in polynomial, often linear, complexity time to control if a given item is a solution or not.Obviously, generating and checking all possible solutions to find a correct one has exponential time complexity, and it is very difficult to obtain with little error margin a solution for them in another way, heuristics for example.
xxxx JQC, 2021, vol.xx, no.xx NP-complete problems are a class of decision problems within NP for which any other problem in NP can be reduced to them in polynomial time.In other words, if you could solve any NP-complete problem in polynomial time, you could solve all problems in NP in polynomial time.Therefore, a polynomial solution, more precisely an exact solution, given to HCP in its general formulation, would imply that , resolving one of the more discussed problems in Computer Science.Here we do not have a similar aim, but we want only to compare some algorithms to find the exact solution with the different computational models, which are the deterministic, probabilistic and quantum ones.
A simple deterministic solution to the HPC, for example, is the following: given a Graph with vertices, generate all permutation of its vertices which begin with 1, and this phase has complexity , where the is for the factorial function; check each permutation: meaning that we have to test if each vertex in the permutation is connected to the next by an edge, and that the last of the sequence is connected by an edge with that numbered 1; for each test we can assume complexity .
So, the whole complexity is that can be approximated to by the known Stirling formula [1].
In the simplest scenarios, that involve small graphs, this class of solutions is broadly used [2][3].With larger graphs, though, a deterministic approach is computationally infeasible.Therefore, probabilistic and quantum algorithms come into play [4]; they do not guarantee finding a Hamiltonian cycle if one exists, but they can be effective in practice.In fact, the trade-off is between computational time, and the quality of the solution; these methods can provide reasonably good solutions within a reasonable time frame for many real-world instances of the HCP.The algorithms also differ by the class of graphs they are appliable to, because some of them are designed to give better solutions on HCP graph models with several constraints (such as the degree of nodes) than the ones that work on every graph.We will see some of these approaches in the Related Works section.
Overall, in this article we compare the most relevant algorithms and results between them and with others designed by ourselves, using HCP as a benchmark and a hint to compare different approaches and models of computation.

Related Works
We know [5] that for the sparse locally connected graphs, HCP is solvable in polynomial complexity time.Sparse locally connected graphs are graphs for which , where are the edges, are the nodes or vertices and is the degree of each vertex, meaning the number of edges entering the node.Furthermore, if a graph is constructed so as to have , with , where is the number of adjacent nodes and with the condition and integers, and if is , that is each node has degree , then for , HCP is in P as shown in [6].
In [7], they design a distributed algorithm that with high probability computes a Hamiltonian cycle in a random graph with , where is the number of the vertices and each possible edge occurs independently with probability .They compute HCP with high probability for this graph class by using nodes as cooperative computing elements and reach the time complexity of .Obviously, they do not obtain this result for a generic graph .
Another way to use probability in HCP solutions is to consider random walks in graphs.This type of research implies to construct a geometric polytope based on the graph to be examined, and using its extreme points, meaning points that do not lie in any open line segment joining two points, as starting point to analyze.Very positive experimental results are shown in [8] by using this type of approach.In [9], they show a quantum computing model in which Hadamard gates are used to obtain all permutations of vertices in a superposition way.Then the Grover algorithm is applied to search for an eventual Hamiltonian cycle.So, in [9] the authors solve HCP for a general graph with high probability, but only a quadratic speedup is obtained compared to the deterministic model of searching classically among all possible solutions.The complexity time of this solution remains exponential.
As they show in [10], for an adiabatic quantum computing model, it is possible to use a particular methodology to obtain some code effectively testable on an existing prototype, the so-known D-Wave.They map the Hamiltonian cycle problem in QUBO problem, the mathematical algorithm for which D-Wave is designed.However, they don't observe an exponential speed-up over the number of nodes of the graph.They also underline problems with noise preparing and testing their examples.
Another quantum information technique for graph algorithms is quantum random walks.For example, in [11] quantum random walks are described for very particular graphs, such as hypercubes and a few tree-based graphs.However, using quantum walks for a generic graph was proved impossible [12].
Based on all these results, we reached the conclusion that very significant results in computational time are reached by restricting the graph classes on the problem instances.
The brute force algorithm presented in the introduction has a time-complexity of .For a generic graph, only some algorithms can outperform it.To introduce them, we also must consider that HCP can be reduced to the Traveling Salesman Problem (TSP).The latter is the problem of finding the minimum cost Hamiltonian cycle in a weighted graph.This is computed representing the graph as a cost matrix , in which the element is the cost of the edge from node to node .Then, it is possible to solve an HCP with an algorithm for TSP, putting in the element of the cost 1 if the edge from to exists, and 2 or more otherwise, and then verifying if the total cost of a TSP solution is equal to the number of nodes of the given graph, or not.Finally, we can apply Bellman-Held-Karp algorithm [13], which has complexity , or the algorithm designed in [14].This latter is a quantum algorithm with complexity .
In addition, many heuristics and strategic approaches exist for TSP, such as Ant Colony Optimization Algorithm, Particle Swarm Optimization Algorithm, Artificial Bee Colony Algorithm and recently Genetic Algorithm [15][16], but they do not find the exact solution efficiently; they only search for one solution near to the optimal.Alternatively, also for TSP, as for HCP, quantum annealing algorithms have been proposed [17][18][19] but they still have too many limitations regarding noise and number of nodes of the graph that have to be elaborated [17].
In the following sections we will present our proposed probabilistic and quantum algorithms.

A probabilistic approach for HCP
Using a random walk approach on a graph , we consider a memory-less path in which, if at the step we are at a node the probability to move to a neighbor is , where is the degree of the vertex .Obviously, the sequence of random nodes is a Markov chain.Now we xxxx JQC, 2021, vol.xx, no.xx add some conditions to the random walk for each single trial, as shown in the following sample of code.Let be the number of the nodes of .
Then we show: 1. // Legend: 2. // Node is the class of every node 3. // is a public member(property) of the node a 4. // == 1 means that there is an edge between node a and b, == 0 means there isn't 5. // == 1 means that the node a has already been visited 6. // is the number of unmarked(unvisited) neighbors of node a 7. // is the number of neighbors of node a 8. // is an array of pointers to every neighbor of node a 9. // chooseRandomNode() is the function that takes a node and returns the next one according to our approach 10. // getRandom() is a function that returns a random index in an array with a weight based on its values (in this // case the probability) Follows: (1)

Theorem 1. Consider a random walk on a graph starting at node v 1 that follows the stop conditions stated in the above algorithm. Let the degree of , that is the number of vertices of adjacent to . Let be the number of vertices of adjacent to , but already visited. Their difference is equal to the number of adjacent vertices to not visited yet (numUnmarked of ). Then, if the condition of Exit (line 30) is true then is a Hamiltonian cycle for and its frequency, as the number of trials tends towards infinite, is:
Proof.The first part is simple to prove.If the condition in line 30 in the algorithm above is true, we have arrived at the step traversing all nodes different from each other.Furthermore, if there is an edge between and , means that there is an edge between the vertex visited at step and the one visited at step 1 numbered 1 as given.So is a Hamiltonian cycle.
We now prove the second statement of our theorem.It simply follows from the relative marking rule (line 29) of the algorithm above.The probability is calculated as product of independent events probabilities.Our algorithm's iteration steps depend on one another.Still, this dependence is already implicit in the term inside the probability designed in it, because at each step we are marking nodes, virtually increasing the term of some node.So, for this the probability that the second step is is and the probability that at the visited nodes are is .Note that is because we haven't visited any nodes yet, so we write instead of .The probability that the random walk visit the sequence is so already given by the final formula of the theorem, and if there is also an edge between the last visited node and the first it is certain that it is true also for the Hamiltonian cycle .
Corollary 1. Considering the rate of success of our algorithm for each Hamiltonian cycle in the graph, and given that each random walk is as time complexity, we can deduce that an upper bound of its expected time complexity is: where, for the sake of simplicity we chose .
Furthermore, if L is a lower bound to the number of Hamiltonian cycles of in the case that is Hamiltonian, then its expected time complexity is: ). ( Proof.Given , considering that the complexity is the inverse of the success probability, and by considering the random walk from every node (hence the factor ), the first formula of the above corollary follows.The second formula instead follows from the first and the corrected hit rate, based on a supposed lower bound of the number of Hamiltonian cycles in the graph, which allows us to increase the probability of finding one, therefore improving the time complexity.
We have designed in such way a probabilistic algorithm that, with high probability, solves for a generic graph with a better time complexity than classical brute-force deterministic algorithm presented in the introduction assuming simply that: However, we remain in an exponential time complexity.
Comparing our algorithm to the quantum computational search algorithm shown in [9], we also can do better but only with the following stronger assumption: f r i n.
( We are not discussing here the advantage of decreasing the degree from to during the random walk.Consequently, our study of time complexity is valid also for perfectly Markov random walks, not based on previous choices.Furthermore, to outperform respectively the best-known classical [13] and quantum [14] algorithm for HCP, the following conditions must be true: ; . ( 7)

The quantum version of our probabilistic algorithm
In this chapter, we show a few quantum versions of our algorithms in a QTM format, as we already did for some known algorithm in [20].
We give the following definition of a Quantum Turing Machine [20][21].
A Quantum Turing Machine (QTM for short) can be seen as the quantum version of a Turing Machine, usually described by the 7-tuple with a condition of a unitary evolution, where:  is the (finite) set of internal states { , and is usually referred to as the current state};  is the input alphabet, is the finite set of symbols called tape alphabet -a sequence of cells containing symbols (one in each cell)-(i.e., ) and it usually contains at least 1-used to code natural numbers in unitary notation-and , the blank symbol;  is the transition function that allows to move from one state to another, giving the amplitude of each step.The square of this function represents the probability of having that step if a measurement occurs.Furthermore, we have the condition and .are allowed moves of the tape head, respectively Left, None -no allowed head move -and Right;  ( a distinguished member of ) is the initial state;  ( a subset of ) is the set of final states (one final state is sufficient).

Here we itemize other relevant features:
 A tape is a pair of strings and such that and w R ;  is the head of the tape whenever is the rightmost symbol of ;  A configuration of is a triple in ;


The initial configuration is represented as where is the input;  A final configuration is where and is the output; we assume that if a final configuration is a superposition of more than one, then all of them are in a final state.
A QTM-computation [15] is a (finite) set of configurations above which determines a mapping a: such that for each represents the amplitude of the transition of from to .This matrix must be unitary.
Consequently, for each configuration and all its next configurations if is the amplitude representing the transition from to a generic configuration , then: where represents the probability of going from to , but all the configurations occur in a parallel way -step by step-until a measurement is effectuated.
Note that after the first step, the starting configuration can be also a superposition of configurations.In this case, the next configuration is determined by the transition function as well but weighting each component of with the relative amplitude.
We now want to give a quantum version of our algorithm.We start with the definition of the following QTM:  ; (12) Each symbol refers to the previous generic definition of a QTM, and represent respectively the symbols for a found Hamiltonian cycle and a not found one, is the blank symbol and is the number of the nodes of a given graph .
Note that with this definition each cell of the tape may contain not only a single symbol and their superposition, but also partial or full paths of the graph and their superposition.
Then, we define with the following rules: , where is a function of the given graph and is supposed to be implemented in a way that we can go easily from a node to its neighbors, we have a QTM that represents the quantum version of our algorithm.
Let be the string contained at step in the input tape at the left of the cursor, then we have: And finally: In (20) returns only if is a Hamiltonian cycle, otherwise returns .Now a measure on the input tape, precisely in the cell relative to the cursor position, that is the cell from origin position, is done.
Function is an oracle, a function that has access to the graph representation in an efficient way.Initially, it starts from node 1 of .It returns a superposition of paths of length 2 ending with 1 neighbor.The cursor moves always right.The oracle function considers all information written in the tape, also because it is summarized at the rightmost position of the written part of the tape-in the last cell exactly.If possible, without revisiting nodes, increments each path of the superposition of next cell node.
When it is not possible, writes the symbol on the tape.This symbol is eventually propagated for all remaining steps of the path.At the last step, which is always the step, determines if there is a Hamilton cycle, that is a length path and an edge to node 1 closing the cycle, and writes for that path the symbol .Otherwise writes .
The probability of finding as a result, given the previously defined , is greater than zero only if the graph is Hamiltonian.In this case, a read operation on the whole tape would result in a Hamiltonian cycle.
Theorem 2. The probability of a hit result in the final measure for the above quantum algorithm is: .(22) xxxx JQC, 2021, vol.xx, no.xx Proof.Indeed, the time of evolution of our algorithm, if we exclude the latest step, the measurement, is exactly steps.But we must consider that all results are processed in the number of repeated trials to have a good probability to measure an result if the graph is Hamiltonian.Also, we must consider that if we measured only the single last cell of the tape, it can have only two symbols, or , because the symbol may be the final symbol of a single or few paths, while the final symbol of a lot of paths processed.The number of paths processed is the same as in our probabilistic algorithm of the previous section.This quantum algorithm reproduces exactly the probabilistic one of the previous section.Indeed, we used the quantum framework to obtain the same functionality and we didn't gain an advantage.With this we demonstrate the Theorem 2. In addition, note that in each of the steps of the processing algorithm we call the function , which we supposed to be linear and however not less than constant as time complexity.In order to make a new measure each trial must run fully and independently.Two corollaries follow.
Corollary 2. The complexity of the above quantum algorithm derives from the repeated number of its executions and measure operations.This must be proportional to the inverse of the probability given in Theorem 2.
Corollary 3. The complexity of the probabilistic and quantum algorithms of Theorem 1 and Theorem 2 respectively are the same.
This follows from what is stated in [22], when quantum computation is not used with all or a large part of its features, often the respective algorithms don't perform computationally faster than probabilistic ones for a similar problem.More in general, we can say that in order to obtain a quantum advantage, it is necessary to rely on purely quantum features rather than trying to replicate a classical version of our problem within a quantum framework.

A quantum interference-based algorithm for HCP
If we want a better result, we may relax some QTM conditions and admit the following modification to the last rules and , substituting them with the following ones: if head , (23) if head , (24) , (25) where is a random extraction of 0 or 1 both with 50% of probability, and with head a function that reads the rightmost position.

Due to
if we read the symbol in the state in a right movement, the transition to another state with the symbol has amplitude or both with probability 0.5.So, it is not a standard QTM anymore, but it is a theoretically valid extension of the original QTM, also because it induces again a unitary transformation on QTM configurations.We obtained a probabilistic QTM that respects the unitary constraint and whose associated amplitudes are functions of the status of the tape and of the state of the machine.The presence of negative interference allows us to access more paths and, if the graph is Hamiltonian, the result of measurement is with higher probability.Consequently, the complexity of our algorithm is better than the one from the previous algorithm version.Theorem 3. The time complexity of the algorithm with the new rules and instead of and is: Proof.The results are affected by negative interference with each other, but in a random way.So, the final weight may be seen as the sum of negative and positive weights in a fully random modality.This behaviour can be described as the equivalent of a particle in a Brownian motion: we have as minimum and maximum expected values after steps, each step consisting of an increment or a decrement of one unit of: .( Consequently, we can derive (26) from our definition of in section 3.1.
So, we have a quadratic speedup, the same obtained applying to our algorithm a quantum search of Grover type [22][23][24], for example in a similar manner that in [9].Now we explain better the oracle function of our quantum algorithm.

Note that, given that i
, where is a neighbor of which has not been visited yet, and is the last node visited of the current partial path, we have: (28) where, as in the non-quantum case, is the degree of the node , and is the number of the already visited neighbors of in the current path.If contains a partial path, and the last node of it has more than one not visited nodes, then is incremented in a superposition way of one node in the next cell.
If all the neighbors of have been visited, and if the length of the path is less then (number of G nodes) or there is no edge , the next symbol added to the path is .Otherwise, if the length of the current path is , and such an edge exists, then the symbol is added to the right of the path.At the end, all superposition paths have length and terminate with or and the necessary steps to evaluate the graph are exactly in all cases.The final states in each superposition are reached at the step.If the graph is Hamiltonian, the last symbol of the tape is a superposition between and .Otherwise, if the examined graph is not Hamiltonian the last symbol will be with no superposition.On the left-hand side of Figure 1, we can see a graph with two partial paths in superposition.We suppose , , , , , , , , belong to , which are the edges of the graph G.If we suppose to be at the fourth walking edge of our algorithm, some superposition path has been generated.Two paths in superstition are and , but for this second one, the next symbol associated to it will be deterministically NH, because from we can go only to node , an already visited node.Two other paths in superposition are and and both have the possibility to go to a not visited neighbor, respectively and for example.
On the right-hand side of Figure 1, we consider the two possible partial paths: and the . For the first one, the next choice can be ,or , each with amplitude ; while for the second path, the choice for the next node can be or , each with amplitude .
All these paths are possible, then they are in superposition.The chosen one will be overwritten on the tape, each weighted with their appropriate amplitude.At each phase, the path length of all superposition paths will be the same.If a path terminates before visiting all possible nodes, from the rules derives that the terminating positions will be filled with the symbol.
The oracle function determines next node together with the amplitude of each choice too.q-our d-max q-our d-20% q-our d-log q-our d-log10  In Figure 2, we show an overview of all the algorithms, classic, probabilistic and quantum ones, shown schematically in Table 1.On the y-axis we represent the expected execution time steps in logarithmic scale.On the x-axis we represent the number of nodes.The first thing that catches the eye is that the classical algorithms can all be over-performed in terms of time complexity by the quantum ones.The brute force classical algorithm (b-f classic) is better than our classical algorithm only for the maximum degree graph class; while obviously the brute force quantum algorithm (b-f quantum) is always better than b-f classic labelled algorithm, this latter being the brute force algorithm that analyzes classically all the possible permutations of the G vertices.B-f quantum is a quantum search-based algorithm that works on all possible permutations; it can be over-performed by our probabilistic algorithm applied to graphs whose degree is limited by the base-ten logarithm of the number of nodes (our d-log10) and obviously by our quantum version with the same graphs class (q-our d-log10).
Following the same criteria, with the labels our d-20% and our d-log, we represent time complexity of our algorithm with parameter d, the maximum degree of the graph nodes, given as limited respectively to the and to the logarithm of nodes number.The respective quantum versions of these algorithms are given by q-our d-20% and q-our d-log.Note that all these algorithms have an exponential time complexity and that only comparing them while they operate on the same classes of graph is correct.

xxxx
In Figure 3, we compare our algorithms with best classical and best quantum known algorithms, respectively indicated with labels best cl and best q.These are over-performed only by the quantum version of our algorithm.Indeed, Figure 2 and Figure 3 show that only our quantum algorithm applied to base-ten logarithm limited degree graph class, labelled q-our d-log10, among those examined, is better than best classical and quantum known algorithms.
Moreover, if we limit to a few hundreds, our quantum algorithm can achieve the same time complexity of q-our d-log10 for every class of graph following this relation: , (29) while our algorithm performs better than best known algorithms also for that tends to infinity if which can be written as: . (31)

Conclusions
We have designed and analyzed a probabilistic algorithm for a Hamiltonian Cycle Problem (HCP), even if without obtaining for the general case a relevant improvement.We also designed two quantum versions of our algorithm, respectively without and with negative interference added.We compared them, the latter in particular, with a classical and a quantum algorithm.In this case, for some classes of graphs, for example, the upper bounded degree graphs, with the assumption of the validity of (31), our algorithm performs better.It outperforms not only the quantum algorithm based on Grover searches on all permutations, but also the best classical and quantum already known algorithms for HCP.
Anyway, we can obtain a quadratic speedup with our quantum algorithm with respect to the classic version of it, only if we use also quantum negative interference and not only quantum superposition.
An interesting aspect arising from this work is the possibility of comparing probabilistic with quantum computational models.Indeed, this work can also be seen as a hybrid approach combining quantum and probabilistic elements.Also, it is worth deepening our knowledge of our version of a QTM, as it is a valid tool for algorithm design.Further studies should be done to compare our algorithm with that written specifically for graphs of bounded average degree, for example those in [25][26].
Another theme that emerges from this work is the exploration of other NP problems and determining under what conditions, with constraints on the original problem or extensions of the quantum model, they become tractable.

Figure 1 :
Figure 1: An example of superposition of two visited paths in a part of the graph G and on the tape, and of the next node choice.Three possible choices are added to the first path and four to the second.The resulting superposition of seven paths is the result of this choice.

Figure 2 :
Figure 2: Comparison between our probabilistic algorithm and different quantum and brute force algorithms

*
Obviously deterministic algorithms are the only ones that can solve the HCP with 100% probability.

Figure 3 :
Figure 3: Comparison between our probabilistic quantum algorithm and the best-known classic and quantum ones

Table 1 :
Final short summary of different algorithms (or the same ones applied to different classes of graph) compared in order of time complexity, for n that tends to infinity