A Mathematical Framework for Maze Solving Using Quantum Walks
Abstract
We provide a mathematical framework for identifying the shortest path in a maze using a Grover walk, which becomes non-unitary by introducing absorbing holes. In this study, we define the maze as a network with vertices connected by unweighted edges. Our analysis of the stationary state of the Grover walk on finite graphs, where we strategically place absorbing holes and self-loops on specific vertices, demonstrates that this approach can effectively solve mazes. By setting arbitrary start and goal vertices in the underlying graph, we obtain the following long-time results: (i) in tree structures, the probability amplitude is concentrated exclusively along the shortest path between start and goal; (ii) in ladder-like structures with additional paths, the probability amplitude is maximized near the shortest path.
1 Introduction
The development of algorithms for finding the shortest path in networks has a rich history [12, 7] and plays an important role in a wide array of practical applications in our daily lives, such as in car navigation systems. The term ’networks’ includes various forms, from physical structures like roads and power lines to more abstract ideas. From the study of networks, a larger field known as complex networks has emerged [34, 5], which has recently expanded its focus to include quantum mechanics [4]. The maze-solving problem can be viewed as a fundamental case of the shortest path problem in networks. Here, we define a maze as a network consisting of unweighted edges that represent distance parameters. Consequently, maze-solving techniques are regarded as a subset of the shortest path problem, with various algorithms, including breadth-first search [9], Dijkstra’s algorithm [11], and the Bellman–Ford algorithm [3], having been developed in classical settings.
The challenge of solving mazes has become an important area of research in the field of natural computing. Various natural phenomena, such as slime molds [27, 35], the Belousov–Zhabotinsky (BZ) reaction [33], electrical discharges [30], and the propagation of light in waveguides [6], have mechanisms that can effectively navigate mazes. While humans typically rely on intelligence to solve such problems, nature’s ability to accomplish the same task highlights that intelligence is not strictly necessary; instead, the key lies in algorithms governed by simple rules.
In exploring networks like mazes, the movement of a probabilistic walker throughout the network represents a specific type of algorithm. In classical exploration methods, the walker corresponds to probability density, while in quantum exploration methods, it relates to probability amplitude. The basic approach to classical exploration is the random walk. Quantum walks have been introduced as the quantum version of random walks and are expected to improve effectiveness in exploration problems because their probability propagation speed is directly proportional to time, unlike random walks, where it is proportional to the square root of time [16, 2]. Furthermore, quantum walks can utilize the interference of probability amplitudes, providing another advantage in exploration tasks.
The maze-solving approach utilizing quantum walks is derived from quantum search [32, 8, 1, 28]. Investigating specific points in a network using quantum walks is similar to implementing Grover’s algorithm on structured networks [17]. Koch et al. extended their research on identifying structural anomalies in networks [15, 22, 10] and demonstrated that executing a Grover walk in a maze—where the vertices at the start and goal undergo phase inversion—can result in the temporary identification of the shortest path [29, 24, 23, 21]. In contrast, Matsuoka et al. advanced the study of quantum walks by accounting for both inflow and outflow [13, 14, 20, 18, 19, 25, 31], creating a more robust and versatile approach [26]. In our paper, by integrating self-loop structures at the maze’s start and goal, along with incorporating holes that absorb probability amplitudes, we introduce the navigation vector which is induced by the fundamental cycles and the shortest path between the pair of the vertices having the self-loop of the underlying graph. Our mathematical results tells us that a quantum walker takes a time to find autonomously the navigation vector, and as a result, it clings along the shortest path between the start and goal of some mazes in the stationary state. Although Matsuoka et al.’s method is not suitable for mazes with cycles that have an odd number of nodes, it has been shown to extend to tree structures and ladder configurations featuring multiple paths. Furthermore, since all time evolution can be expressed as the problem of matrix exponentiation defined by the network structure, this approach enables efficient computations using GPUs, independent of the number of steps or vertices, suggesting its potential as a classical algorithm inspired by quantum mechanics.
In this paper, we present a mathematical reconstruction of the maze-solving method utilizing Grover walk, leading to an explicit derivation of its limit distribution. In Section 2, we outline the detailed structure of the graph that represents the maze and discuss the time evolution of the Grover walk. We also examine the spectral properties of the Grover walk in this context, demonstrating that the probability distribution in the long-time limit is determined by the overlap between the initial state and the eigenspace associated with the eigenvalue , known as the navigation vector. In Section 3, we detail the limit distribution of the Grover walk specifically for tree structures and ladder graphs.
2 Settings and properties of Grover walk
2.1 Settings
Let be a finite connected and symmetric digraph such that an arc if and only if its inverse arc . The origin and terminal vertices of are denoted by and , respectively. We assume that has no multiple arcs and self-loops. This symmetric digraph is called the underlying graph.
In this paper, we consider the problem of solving a maze by using a quantum walk. The maze is regarded as the underlying graph . To let the quantum walk solve the maze, we slightly deform the underlying graph as follows. The start and goal of the maze can be placed at any vertex in , and they are indexed by and , respectively. To find a route from to , we add one self-loop each to vertices and , which are also indexed by and . We also add a vertex which is called sink and indexed by . The sink is connected only to the start vertex . The arc which connects and is also indexed by , where and . In the following, the graph induced by the underlying graph is denoted by ; the digraph contains these self-loops, the sink vertex and arcs connecting to the start and the sink vertices. (See Figure 1). The degree of is given by
By the symmetry of the digraph, the equation holds.

The Hilbert space w.r.t. arcs is defined by
We use the Grover walk on defined by
for any . The initial state is
We want to assume that the quantum walker at the sink goes away and never comes back. To represent this, we use the projection given by
(2.1) |
For , the -th iteration of the Grover walk with the sink is defined by
Then, the finding probability at vertex and at time can be defined by
Remark that our assumption is also represented by using an infinite dimensional environmental Hilbert space and an appropriately extended unitary on [25]. However, since
for any , we will adopt the RHS represented by the finite system in this paper. Here is the extension of the initial state to .
2.2 Spectral decomposition of for maze solving
To solve the maze, it is important to know the eigenvalues and eigenvectors of the Grover walk . In particular, we focus on the eigenvectors of which are invariant under the action of the projection ; as we will see, the contribution of the eigenvectors which are not invariant under the action of reduces exponentially to as the time step goes to infinity.
We give the following simple lemma which will be useful for the considerations of its remaining statements. Remark that the eigenvalue of satisfies .
Lemma 2.1
Let be an eigenvector of associated with the eigenvalue . Then, .
Proof. By the definition of Grover walk, we have
Then, implies .
Since our interest is the time iteration of the truncated Grover walk with respect to , that is, , and the support of the initial state is the self-loop of the start vertex, we will decompose the Grover walk through the consideration of the overlap between an eigenvector and . The final form of the spectral decomposition can be seen in (2.2). Then, we consider the eigenvectors of . For an eigenvector of , there are the following four cases:
(1) (2) ,
(3) , (4) .
Note that by Lemma 2.1, implies , and implies .
When a vector satisfies the case , we say “ is in ”, for simplicity.
The eigenspace associated with the eigenvalue is denoted by . Note that the eigenvectors in (1) or (4) have the contribution to give the iteration of the truncated Grover walk , because for any in (1) or (4). First, we consider the eigenspace because of the following strong statement.
Lemma 2.2
Assume that the eigenvector is in (1). Then, must be an eigenvector of the eigenvalue .
Proof. Let be the set of all arcs which satisfy , where and . Let have the eigenvalue . Since and
we have . Therefore,
By the assumption , we have .
The statement of Lemma 2.2 is strong but not ensures the existence of such an eigenvector. However, the following lemma not only ensures such an eigenvector in Lemma 2.2 but also gives an explicit expression by using a path between the self-loops and . Figure 2 illustrates this eigenvector.
Lemma 2.3
There exists an eigenvector such that is in (1).
Proof. Let be a path which satisfies , , , , and , and let and . Define a vector by

Then, it is easy to check that is an eigenvector in . (See Figure 2.)
Lemmas 2.2 and 2.3 imply that every eigenvector in (1) is included in . Then, we are interested in whether includes eigenvectors in (2), (3) or (4). Let us see that the following lemma removes the possibilities that is in (2) or (3).
Lemma 2.4
Every eigenvector in satisfies , that is , is in (1) or (4).
Proof. Let be an eigenvector in . We use the same setting as in the proof of Lemma 2.2. Similar to the proof of Lemma 2.2,
Hence, . Since by Lemma 2.1,
This implies .
Now we are ready to construct an ONB for as follows.
Proposition 2.5
There exists an ONB of such that is in (1) and is in .
Proof. Let , and let be a bases of with . We can take such a basis by setting to be in (1). Define a vector by
Remark that is in (4) for . We apply the Gram-Schmidt process to , and denote the constructed vectors by . This is the desired ONB.
The reason for choosing such an ONB of is as follows. To describe the Fourier expansion of the initial state , we use the inner products of each vector in an ONB and . Note that the first bases of in Proposition 2.5, (), have no overlap to the initial state , that is, for any . The only base which has the overlap with is the last base . Thus the overlap of the initial state with the subspace is obtained by just one inner product of and by this expression of ONB. As we will see, the contribution of with to the survival probability exponentially reduces. Thus the vector is the key to navigates the quantum walker to the stationary state.
Next, we are interested in the contribution of the eigenspace of having the overlap with the initial state for the eigenvalue to the survival probability. To this end, we construct an ONB of with step by step; the final form of the decomposition of for the survival probability is described in (2.2). First, we show that every eigenvector with the eigenvalue is not in (2), or is not in (3) as follows.
Lemma 2.6
Suppose . does not contain both of vectors in (2) and (3).
Proof. When is in (2) and is in (3), we can construct an eigenvector in (1) using a linear combination. Then, by Lemma 2.2, which is contradiction.
Using Lemma 2.6, we can construct the following ONB for concerning to the overlap with and .
Proposition 2.7
There exists an ONB of such that at most one vector in the ONB is in (2) or (3).
Proof. If there is no vector in (2) or (3) in , then all vectors in are in (4), and we can construct the desired ONB, easily.
If there is a vector in (2) or (3), we can use the same method in the proof of Proposition 2.5. Assume that there is a vector in (2). Let , and let be a basis of with and . Define a vector by
Remark that is in (4) for , because and there is no vector in (1). We apply the Gram-Schmidt process to , and denote the constructed vectors by . This is the desired ONB.
When there is a vector in (3), we can construct the desired ONB, similarly.
We denote by the number of vectors in (4) in the above ONB, and put . When the above ONB contains a vector in (2) or (3), we denote the vector by . This means .
Here, we consider the spectrum decomposition of , that is,
(2.2) |
where is the set of all eigenvalues of , and when does not contain a vector in (2) or (3). Define . We see that this subspace is invariant under defined in (2.1).
Lemma 2.8
is invariant under , that is, .
Proof. Remark that and . It is sufficient to prove that is orthogonal to and . For , we have
Similarly, we can check that is orthogonal to .
This Lemma implies that the contribution of the subspace to the survival probability reduces exponentially to zero as time goes to infinity as follows.
Proposition 2.9
A vector satisfies .
Proof. Since is invariant under by Lemma 2.8, it is enough to prove that the absolute value of the eigenvalue of is less than .
Assume that is an eigenvalue of with , and is a unit eigenvector associated with the eigenvalue . The equation
implies , and therefore, . Hence, we have
which means that is an eigenvector of . Moreover, .
Since has the eigenvalue , is in . On the other hand, is in . Hence, is equal to for some . However, this contradicts .
The initial state is written as
So,
We will call this vector the navigation vector. Recall that the navigation vector is the unique base of which has an overlap to , see Proposition 2.5. We use this navigation vector to solve the maze because the survival probability can be simply described by only the overlap of the initial state and the navigation vector:
Proposition 2.10
Let be the probability at position at time , and be the navigation vector defined the above. Then we have
Therefore, finding the ONB in Proposition 2.5 so that the navigation vector appears is the key to obtain the survival probability. We demonstrate the construction of the ONB and the navigation vector for a tree case and a ladder case in the next section.
3 Maze solving
3.1 Tree case
When the graph is a tree, we can determine the navigation vector.
Theorem 3.1
When the underlying graph is a tree, the navigation vector is constant multiple of the vector defined in the proof of Lemma 2.3.
Proof. When the underlying graph is bipartite, the dimension of is given by [25, Proposition 6 for Case (C)]. Note that for tree case, the Betti number becomes . Then . On the other hand, the navigation vector and the vector defined in Lemma 2.3 are both in . These imply the assertion of this theorem.
When the underlying graph is a tree, the shortest route from the start to the goal is uniquely determined which is denoted by . We set and . Let be navigation vector, and let . Then, the navigation vector satisfies
This means that the amplitudes of the navigation vector are only on the shortest route. Therefore, the position of the quantum walker tells us the shortest route.
3.2 The case the graph has cycles
Note that a tree has the unique simple path between the start and goal vertices, and this becomes the shortest path. Here, a simple path is a walk in which all vertices and also all edges are distinct. We have seen in Section 3.1 that the shortest path of arbitrary tree is only the place where a quantum walker “clings” in the long time limit. On the other hand, once there is a cycle, there are several choices of the non-backtracking path. As a natural question, we are interested in the tendency of a quantum walker in this case. In this section, we consider a ladder graph as an example of the graph which has cycles so that there are kinds of “detours” among the shortest path. See Figure 4. Before describing the setting, we prove the next lemma.
Lemma 3.2
For a cycle of length , there exists an eigenvector of the Grover walk associated with the eigenvalue .
Proof. Let be a cycle of length , that is, , and . Define a vector by
This is the desired eigenvector. (See Figure 3.)

Now, we consider a ladder graph. As in Figure 4, the ladder graph contains cycles which are indexed by . Each cycle is a rectangle of length and width . The lower left vertex of the cycle and the start vertex are adjacent.

The normalized eigenvector with respect to the cycle constructed in Lemma 3.2 is also denoted by , and the normalized eigenvector with respect to the shortest route defined in Lemma 2.3 is denoted by . Without loss of generality, we can assume and . It is known that the eigenvector of associated with the eigenvalue is described as a linear combination of and [25]. Indeed, it holds that , where ’s are the eigenvectors of the eigenvalue in (2.2) whose supports have no intersection to . To obtain the navigation vector in (2.2), from now on, we construct the ONB of in Proposition 2.5 by applying the Gram-Schmidt process to step by step.
Lemma 3.3
The equations
hold.
Proof. The first and second equations are obvious by the definition of and . The inner product in the third equation can be calculated as
because of the assumption
Let . We apply the Gram-Schmidt process to . Since is in (4) and is in (1), the constructed ONB is the ONB in Proposition 2.5. We denote this by . Then, is the navigate vector.
First, we consider about and . Let be the second kind of Chebyshev polynomial, and define .
Proposition 3.4
The equation
holds.
Proof. By and Lemma 3.3,
for . Since , . These equations imply , where . Here, we put
where . Remark that and . Since is the normalization of and , is positive. Moreover,
implies , and implies . The equation means that and have the same sign, and therefore, is positive for . To calculate and , we use Chebyshev polynomial. We claim that
where . Indeed, we can prove this using a similar method to the proof in [31], or we can check that these and satisfy the above recurrence relations.
By this fact and , we have
which is the assertion.
Next, we consider about and . Define a projection by
is also the projection onto . Here, is written as
Lemma 3.5
Proposition 3.6
The navigation vector is written as
By this proposition, we can calculate for an arc , explicitly. Let be an arc on the left side of the cycle . If , . Moreover, by the assumption , . Hence, when , we have
When , just multiply the above equation by . Similarly, when is an arc on the left side of the cycle for and ,
When , just multiply the above equation by .
In order to compare these values, we prepare the next lemma.
Lemma 3.7
The following inequalities hold for :
Proof. (1) Let . When , and . Since , we have . If the inequality is true for , we have
Hence, we obtain the assertion by induction.
(2) We can calculate as
(3) By using the partial fraction decomposition,
We use (2) for the last inequality.
The next proposition shows that the probability of finding the quantum walker at the left hand side of is monotonically decrease.
Theorem 3.8
Let be an arc on the left side of the cycle for . Then, the inequality
holds for .
When , it is enough to show
We can calculate as
When , we need to show
Here, we have
which shows the assertion.
When is an arc on the top side of the cycle for and ,
When , just multiply the above equation by . The next proposition shows that the probability of finding the quantum walker at the top side of is also monotonically decrease.
Theorem 3.9
Let be an arc on the top side of cycle for . Then, the inequality
holds for .
Proposition 3.6 says that the amplitude of the navigation vector may not be zero even at a point outside of the shortest route from the start to the goal. On the other hand, Theorems 3.8 and 3.9 show that the quantum walker is more likely to be at a point on a shorter route. Hence, in the case of ladder graph, the position of the quantum walker tells us a shorter route, although not as much as in the case of tree graph.
3.3 Comparison with the digraph with a sink at the goal
A method of maze-solving was considered by adding the sink at the goal in [26]. In this subsection, we discuss differences between the method in [26] and ours.
Example 3.10
The digraph in the left hand side of Figure 5 is considered in [26]. When we put the sink at the goal, the state does not converge. The reason why this happens is that there exists an eigenvector in (1) whose eigenvalue is not . Let and . Then, the vector defined as in the right hand side of Figure 5 is the eigenvector associated with the eigenvalue . This eigenvector is the cause of oscillations of amplitudes (See [25, 26]).

On the other hand, when we put the sink at the start, the state definitely converges. (See also Section 3.2.)
Example 3.11
When the sink is at the goal, we can make an example where the amplitudes of the state appear at points other than the start-to-goal path. Let and . Then, the vector defined as in Figure 6 is in (1) whose eigenvalue is not .

Therefore, always has non-zero coefficients on the cycle of length . This means that the position of the quantum walker does not tells us the shortest route. Probably, it misleads us.
4 Summary
We have established a mathematical framework for maze solving using quantum walks and explicitly derived the limit distribution. Our method resembles the placement of food at the start and goal in slime mold maze-solving by incorporating self-loops at these vertices, which enables the emergence of the shortest path within the quantum walk structure. Moreover, we found that adding the sink at the start rather than at the goal effectively prevents the emergence of unstable states. These phenomena are based on the spectral properties of the Grover walk, characterized by a birth space defined by fundamental cycles, self-loops, and sinks. Although this eigenspace has not been utilized in existing quantum search algorithms, it plays an important role in our maze-solving methodology.
Acknowledgments
E.S. is supported by JSPS KAKENHI Grant Number 24K06863. H.O. is supported by JSPS KAKENHI Grant Number 23K03147.
References
- [1] S. Aaronson and A. Ambainis. Quantum search of spatial regions. Theory of Computing, 1(4):47–79, 2005.
- [2] A. Ambainis, E. Bach, A. Nayak, A. Vishwanath, and J. Watrous. One-dimensional quantum walks. Proc. 33rd Annual ACM Symp. Theory of Computing, pages 37–49, 2001.
- [3] R. Bellman. On a routing problem. Quarterly of Applied Mathematics, 16:87–90, 1958.
- [4] J. Biamonte, M. Faccin, and M. D. Domenico. Complex networks from classical to quantum. Commun Phys, 2:53, 2019.
- [5] S. Boccaletti, V. Latora, Y. Moreno, M. Chavez, and D.-U. Hwang. Complex networks: Structure and dynamics. Physics Reports, 424(4):175–308, 2006.
- [6] F. Caruso, A. Crespi, A. Ciriolo, F. Sciarrino, and R. Osellame. Fast escape of a quantum walker from an integrated photonic maze. Nat Commun., 7:11682, 2016.
- [7] B. V. Cherkassky, A. V. Goldberg, and T. Radzik. Shortest paths algorithms: Theory and experimental evaluation. Mathematical Programming, 73:129–174, 1996.
- [8] A. M. Childs and J. Goldstone. Spatial search by quantum walk. Phys. Rev. A, 70:022314, Aug 2004.
- [9] T. Cormen, C. Leiserson, R. Rivest, and C. Stein. Introduction to Algorithms 3rd ed. 2009.
- [10] S. Cottrell and M. Hillery. Finding structural anomalies in star graphs using quantum walks. Phys. Rev. Lett., 112:030501, Jan 2014.
- [11] E. Dijkstra. A note on two problems in connexion with graphs. Numer. Math., 1:269–271, 1959.
- [12] S. Dreyfus. An appraisal of some shortest path algorithm. Oper. Res., 17:395–412, 06 1969.
- [13] E. Feldman and M. Hillery. Quantum walks on graphs and quantum scattering theory. Contemporary Mathematics, 381:71–96, 2005.
- [14] E. Feldman and M. Hillery. Modifying quantum walks: A scattering theory approach. Journal of Physics A: Mathematical and Theoretical, 40:11319, 2007.
- [15] E. Feldman, M. Hillery, H.-W. Lee, D. Reitzner, H. Zheng, and V. Bužek. Finding structural anomalies in graphs by means of quantum walks. Phys. Rev. A, 82:040301, Oct 2010.
- [16] R. P. Feynman and A. R. Hibbs. Quantum Mechanics and Path Integrals. 2010.
- [17] L. K. Grover. Quantum mechanics helps in searching for a needle in a haystack. Phys. Rev. Lett., 79:325–328, Jul 1997.
- [18] Y. Higuchi, M. Sabri, and E. Segawa. Electric circuit induced by quantum walk. Journal of Statistical Physics, 181:603––617, 2020.
- [19] Y. Higuchi and E. Segawa. Circuit equation of Grover walk. Annales Henri Poincaré in press, arXiv:2211.00920.
- [20] Y. Higuchi and E. Segawa. Dynamical system induced by quantum walks. Journal of Physics A: Mathematical and Theoretical, 52:39520, 2019.
- [21] M. Hillery. Finding more than one path through a simple maze with a quantum walk. Journal of Physics A: Mathematical and Theoretical, 54(9):095301, feb 2021.
- [22] M. Hillery, H. Zheng, E. Feldman, D. Reitzner, and V. Bužek. Quantum walks as a probe of structural anomalies in graphs. Phys. Rev. A, 85:062325, Jun 2012.
- [23] D. Koch. Scattering quantum random walks on square grids and randomly generated mazes. Phys. Rev. A, 99:012330, Jan 2019.
- [24] D. Koch and M. Hillery. Finding paths in tree graphs with a quantum walk. Phys. Rev. A, 97:012308, Jan 2018.
- [25] N. Konno, E. Segawa, and M. Stefanak. Relation between quantum walks with tails and quantum walks with sinks on finite graphs. Symmetry, 13:1169, 2021.
- [26] L. Matsuoka, K. Yuki, H. Lavička, and E. Segawa. Maze solving by a quantum walk with sinks and self-loops: Numerical analysis. Symmetry, 13:2263, 2021.
- [27] T. Nakagaki, H. Yamada, and A. T’oth. Maze-solving by an amoeboid organism. Nature 407, 407:470, 2000.
- [28] R. Portugal. Quantum Walk and Search Algorithm, 2nd Ed. Springer Nature Switzerland, 2018.
- [29] D. Reitzner, M. Hillery, and D. Koch. Finding paths with quantum walks or quantum walking through a maze. Phys. Rev. A, 96:032323, Sep 2017.
- [30] D. R. Reyes, M. M. Ghanem, G. M. Whitesides, and A. Manz. Glow discharge in microfluidic chips for visible analog computing. Lab Chip, 2:113–116, 2002.
- [31] E. Segawa, S. Koyama, N. Konno, and M. Štefaňák. Survival probability of the grover walk on the ladder graph. Journal of Physics A: Mathematical and Theoretical, 56:215301, 2023.
- [32] N. Shenvi, J. Kempe, and K. B. Whaley. Quantum random-walk search algorithm. Phys. Rev. A, 67:052307, May 2003.
- [33] O. Steinbock, Ágota Tóth, and K. Showalter. Navigating complex labyrinths: Optimal paths from chemical waves. Science, 267(5199):868–871, 1995.
- [34] S. Strogatz. Exploring complex networks. Nature, 410:268–276, 2001.
- [35] A. Teroa, R. Kobayashia, and T. Nakagaki. A mathematical model for adaptive transport network in path finding by true slime mold. Journal of Theoretical Biology, 244:553–564, 2007.