Efficient Catalytic Graph Algorithms
Abstract
We give fast, simple, and implementable catalytic logspace algorithms for two fundamental graph problems.
First, a randomized catalytic algorithm for connectivity running in time, and a deterministic catalytic algorithm for the same running in time. The former algorithm is the first algorithmic use of randomization in . The algorithm uses one register per vertex and repeatedly “pushes” values along the edges in the graph.
Second, a deterministic catalytic algorithm for simulating random walks which in time estimates the probability a -step random walk ends at a given vertex within additive error. The algorithm uses one register for each vertex and increments it at each visit to ensure repeated visits follow different outgoing edges.
Prior catalytic algorithms for both problems did not have explicit runtime bounds beyond being polynomial in .
Keywords and phrases:
catalytic computing, graph algorithms, catalytic logspaceFunding:
Edward Pyne: Supported by NSF award CCF-2310818.Copyright and License:
2012 ACM Subject Classification:
Theory of computation Graph algorithms analysis ; Theory of computation Pseudorandomness and derandomization ; Theory of computation Complexity classesAcknowledgements:
E.P. thanks Ryan Williams for encouragement to think about algorithms in CL and useful discussions, and Ian Mertz for the suggestion to work over different moduli. J.C. thanks Michal Koucký and the CCC reviewers for useful suggestions.Editor:
Shubhangi SarafSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
1.1 Catalytic space
In the catalytic space model, an algorithm has two tapes to use as memory: a smaller ordinary tape, and a larger “catalytic” tape which starts out filled with arbitrary data. The algorithm may freely write to and read from both tapes, but when it finishes, the catalytic tape’s original content must be restored. Often the working tape has size and the catalytic tape has size , defining the decision class catalytic logspace or . Buhrman, Cleve, Koucký, Loff and Speelman [2] initiated the study of this model with their surprising result that evaluation of logarithmic depth threshold circuits was possible in , from which it follows for example that connectivity and estimation of random walks (the complete problems for nondeterministic logspace () and randomized logspace () respectively) are in .
Broadly speaking, two ways to take advantage of catalytic space have been explored previously: compression-based techniques are able to make use of incompressible catalytic tapes (as randomness, for example); and algebra-based techniques treat the tape as an array of registers which they use to execute a “straight-line program”, a pre-determined sequence of mathematical operations. The original result is an example of the algebraic approach. The compression-based approach began with a “compress-or-random” argument that (Mertz [8] gives a sketch of it). Several subsequent works [6, 10, 5, 7] applied this technique further, with Cook, Li, Mertz and Pyne [5] using it to derandomize randomized itself. All of these results in both branches have a “complexity” flavor – in particular, the runtime for the relevant problem is some large polynomial.111Cook [4] implemented a register program for connectivity with an estimated runtime of , and catalytic tape size .
We give new techniques for deciding graph connectivity and estimating random walks. Our algorithms are very simple and implementable, and allow a precise analysis of the catalytic space consumption and runtime.222For the runtime bounds, we assume we have RAM access to the catalytic tape and oracle access to the graph. This does not affect the structure of the class (as we can simulate a catalytic RAM with a standard catalytic machine with a polynomial slowdown). We hope this will initiate the study of from an algorithmic perspective.
1.2 Our Results: Connectivity
We first state our results for connectivity, beginning with our deterministic algorithm:
Theorem 1.
There is a catalytic algorithm that, given a simple directed graph with vertices and edges together with vertices , decides whether there exists a path from to . The algorithm uses workspace and catalytic space, and runs in time .
Next, we give a randomized algorithm that improves the runtime to and space usage to , only a factor of in runtime from the linear-workspace BFS algorithm:
Theorem 2.
There is a randomized catalytic algorithm that, given a simple directed graph with vertices and edges together with vertices , decides whether there exists a path from to . The algorithm uses workspace and catalytic space, and runs in time .
We remark that a randomized (one-sided error) catalytic algorithm always resets the catalytic tape no matter the random coins. If there is no path, the algorithm always returns no, and if there is an path returns yes with probability at least .
As far as we know, this result is the first use for randomness in catalytic computing – rather than using it to place a new problem in the class (now provably impossible [5]), we use it to give an algorithmic speedup.
Remark 3.
The best known algorithms for stconn either use space and superpolynomial time [11], or polynomial time and slightly sublinear space [1]. Under the assumption there does not exist a randomized stconn algorithm that simultaneously uses space and polynomial time, the catalytic space usage of Theorem 2 is optimal up to subpolynomial factors.333A randomized catalytic logspace algorithm for connectivity using catalytic space would imply a randomized space, polynomial-time algorithm for connectivity [2]. We view matching the total space of [1] with a catalytic algorithm to be an interesting open question.
In fact, we can obtain an additional desirable property. The practical motivation for is to borrow temporarily unused space to perform useful computation. Unfortunately, if any part of the borrowed section of memory is needed during the computation of the catalytic machine, the original owner may need to wait for the entire catalytic computation to finish. As such, existing catalytic algorithms do not seem to permit sharing a single section of memory without huge latency.444Alongside the large runtime of prior algorithms, this was mentioned as the primary issue for practical catalytic computing by Cook [4]. To rectify this problem, we define a notion of catalytic algorithms that must permit fast query access to the original memory configuration at all times:
Definition 4.
A catalytic algorithm is locally revertible in time if at any point during the execution of with initial tape , the algorithm can be paused and queried on an index , and will return in time (and then continue its execution).
We show that (at the cost of polynomially more catalytic space) our randomized connectivity algorithm can be made locally revertible for :
Theorem 5.
There is a randomized catalytic algorithm that, given a simple directed graph with vertices and edges together with vertices , decides whether there exists a path from to . The algorithm uses workspace and catalytic space, and runs in time . Moreover, the algorithm is locally revertible in time .
As far as we are aware, no previous catalytic algorithm is locally revertible for any time bound smaller than its runtime. This new property strengthens the motivation for catalytic space: rather than borrowing an unused hard drive, the catalytic algorithm only needs to borrow the ability to write to that hard drive, since at all times the original data will be accessible for reading with small latency.
1.3 Our Results: Random Walks
Next, we give an efficient catalytic simulation of random walks:
Theorem 6 (random walk on a general graph).
There is a catalytic algorithm that, given a graph with vertices and edges, together with vertices and parameters , returns such that
The algorithm runs in time and uses workspace and catalytic space.
Prior algorithms for random walks are primarily based on logspace derandomization techniques that are not practically efficient. For estimating sub-polynomial length walks to inverse sub-polynomial error, our algorithm runs in almost linear time .
If is guaranteed to be acyclic, the algorithm can be made to use less time and space by skipping a transformation that removes cycles (see Theorem 21). Alternatively, naïvely applying the algorithm for acyclic graphs on a graph with cycles produces an interesting result: the algorithm is no longer catalytic, but produces a walk with visit counts matching a true random walk’s stationary distribution, after a number of steps which depends on the mixing time. For details, see Theorem 29.
1.4 Our Technique: Connectivity
We will give a catalytic algorithm that, given a graph on vertices, determines if there exists a path from to . We virtually lift to a layered graph on layers with vertex set , where we place an edge from to if .
Next, for every and timestep , allocate an bit register on the catalytic tape, which we denote , and interpret the register as a number in . Let the initial value of the register be .
We define an edge push as, for an edge in the lifted graph, setting
For each layer in sequence, we perform an edge push for every edge in the layer.
Let be the final value of after pushing along every edge. Note that we can easily revert the catalytic tape by performing a reverse edge push on every edge in every layer, where we subtract the register instead of adding. Now consider incrementing (i.e. the register of the start vertex in the first layer) by and performing the same sequence of edge pushes; let the new final value of be . We show via an inductive argument that is exactly the number of length- paths from to , modulo (and by adding a self-loop to we can assume that if an path exists, there exists an path of length ). By repeatedly executing the edge push sequence and comparing to bit by bit, we determine whether their difference is nonzero – equivalently, whether there exists an path.
Improving the runtime with randomness
Unfortunately, since the number of paths from to can be exponential in and we count the number of paths mod the register size, our deterministic algorithm must take the register size to be , so pushing a single edge takes linear time. Moreover, we must compute the entire sequence of pushes times to compare to . To avoid this slowdown, we use randomness. Instead of working mod for , we pick a random small modulus and work mod . If the number of paths is nonzero, with reasonable probability we will have
from which the algorithm can infer that there is a path from to . In this way, we reduce the size of each register to bits.
If is not a power of two, not all strings of length will correspond to values mod , so we must ensure that each register is “valid” before running the algorithm. This problem was solved before by Buhrman et. al. [2, Lemma 15], but their approach is not fast enough for us. Instead, we use a larger modulus chosen so that is small, and then draw a random shift (which we record on the worktape) and add to every register. With high probability over , this ensures every register contains a value less than (and otherwise we abort).
Local revertibility
Next, we discuss how to achieve local revertibility. After performing all edge pushes onto a register , the current value of this register is exactly its original value plus
where is the current value of the register in the previous layer. Thus, if we receive a query for the initial value of this register, we can iterate over the in-neighbors of , subtract off the register values of the previous layer, and thus return . The time for this operation is essentially the product of the in-degree of and register size. Since we have already reduced the register size to , it suffices to ensure our graph has bounded in-degree, which we show we can do with a standard transformation (Lemma 12).
Decreasing the number of registers
Finally, as written we use registers, one per vertex and timestep. In fact, we can simply use two sets of registers, one for odd and one for even timesteps, and alternate. This saves a factor of in space, but breaks local revertibility. The version of our algorithm with this modification is Theorem 18.
1.5 Our Technique: Random Walks
In this introduction, for simplicity, we will assume the graph is acyclic and 2-outregular, with each vertex having a edge and edge. We will determine the probability that a random walk from ends at with additive error at most .
Allocate one bit of the catalytic tape for each vertex. For vertex , denote this register . Run walks from as follows. At vertex , we take the edge labeled with the current value of , then set . In this way, if we examine walks reaching over the course of the walks, the next edges taken are or . The top row of Figure 2 shows an example of this process, with the bits of the catalytic tape drawn directly on the corresponding vertices as or .
Now we can argue that the number of visits to each vertex approximately equals the expected number of visits if we had done a truly random walk. A common way to prove this kind of result is with a “local consistency check” – see for example Nisan’s Lemma 2.6 [9, 3].
The general idea is that if every vertex is given a pseudorandom bit of approximately as many times as it is given a , then each vertex is visited approximately the right number of times. Our version of this argument appears in the proof of Lemma 25. By a careful analysis we show that the number of visits to each vertex is within of its expected value, regardless of the number of simulations. Thus after simulations, we obtain additive error at most .
Remark 7.
Our runtime is linear in , which is better than the dependence of the algorithm that simply takes true random walks. For some intuition on how the algorithm achieves this, note that for every vertex that has been visited times, every out-edge is visited times, whereas for a true random walk, we would expect a deviation on the order of .
Finally, we must restore the catalytic tape. This is done by running the “reverse” of our simulations. We do not literally walk in reverse; rather, we walk forward as before, but slightly change the way we supply random bits, so that each “reverse” walk exactly undoes the effect of one normal walk. For details, see Algorithm 2 and Corollary 27.
1.6 Summary of Contributions
From a complexity perspective, neither result places new problems in catalytic logspace. However, we view these algorithms as having two main advantages over prior work. First, the techniques are simple and clearly demonstrate the power of catalytic computation. Second, this simplicity allows us to give concrete bounds on their resource usage (both catalytic space and time). We view algorithms in catalytic space as worthy of further study; we have no reason to suspect our runtimes are optimal. In addition, we are interested in whether other catalytic algorithms can be made locally revertible.
2 Preliminaries
We denote the natural numbers, and for we denote the natural numbers less than .
For a vertex in a directed graph, is the number of incoming and is the number of outgoing edges.
We require a very weak bound on the number of paths in a graph:
Fact 8.
For an -vertex graph (possibly with self-loops), the number of length- paths between any two vertices is at most .
We assume basic familiarity with word-RAM and catalytic machines. For concreteness, we give a (not entirely formal) definition of catalytic RAM machines.
Definition 9 (Catalytic RAM Machine).
We say is a catalytic RAM machine that computes a function using time, workspace, and catalytic space if it works as follows. The machine is given read-only access to , read-write access to bits of workspace, read-write access to a catalytic tape of length in initial configuration , and write-only access to an output tape.
Furthermore, we allow the algorithm query access to the catalytic tape, in that it can read and write a specified bit in constant time after writing the index of this bit to a dedicated query tape. For every and , we have that the machine halts in at most steps with on the output tape and the catalytic tape restored to .
Our definition is not powerful enough to allow analysis of runtimes without polylog factors from query overheads, and we do not attempt this.
2.1 Catalytic Registers
It is often convenient for an algorithm to view its catalytic space as consisting of registers for doing arithmetic over some modulus . If is a power of two, this is straightforward: allocate bits per register. However, our faster randomized connectivity algorithms (Theorems 2 and 5) need to work with arbitrary moduli , which creates a difficulty: if we allocate bits of the catalytic tape to each register, some registers may start with values outside the range .
Buhrman, Cleve, Koucký, Loff and Speelman [2, Lemma 15] have a clever solution to this problem which unfortunately is too slow for our purposes. Instead, we do the following.
Choose to be a constant factor larger than , and treat the -bit string as an element of , where is the largest value such that . We say is valid for (modulus) if its initial value is less than , and otherwise we say is invalid.
Our algorithm ensures its registers are valid by applying a shift to all registers simultaneously.
Fact 10.
For an -bit register with initial configuration , over a uniformly random shift , is valid for with probability greater than .
Each valid register can be decomposed as having value ; to do arithmetic modulo , we leave fixed and only change the part. It is easy to see these operations can be computed in simultaneous time and space , given as input. For valid registers over modulus , we let to be this operation.
Now that we can implement registers over arbitrary moduli, the following straightforward lemma lets us use them to check whether counts over a much larger domain are nonzero:
Lemma 11.
Let be arbitrary. For a uniformly random , the probability that is at most .
Proof.
Note that can have at most distinct prime factors, and for every prime that is not one of these factors we have that . Moreover, a random element in is prime with probability by the Prime Number Theorem. Thus, if we consider the interval , this interval contains at least primes, of which at most divide , so the probability that we draw a prime that does not divide is at least
2.2 Input Representation
Because our catalytic algorithms do not have the space to perform otherwise standard transformations on the graph (for instance, producing an adjacency list given an adjacency matrix), we must be careful with how they access the input. We adopt the model of oracle access, which is common in sublinear and local models. We say we have oracle access to a graph if its vertex set is for some , and for any we can make the following queries:
-
(resp. ) returns the in-degree (resp. out-degree ).
-
(resp. ) returns the th in-neighbor (resp. out-neighbor) of , or if this does not exist.
Our connectivity algorithms only use in-edge access to the graph, and our random walk algorithms only use out-edge access.
For the locally revertible connectivity algorithm (Theorem 5), we use that given a graph, we can provide oracle access to a modified graph with bounded in-degree:
Lemma 12.
Given oracle access to a directed graph with vertices and edges, where every vertex has in-degree at most , there is a simulation of an oracle for a graph on vertices with the following properties:
-
The simulation can answer queries in space and time, with the exception of queries.
-
The maximum in-degree is .
-
The diameter is .
-
For vertices , there is an path in if and only if there is an path in . (We have , so integers representing vertices of also represent vertices of .)
All but of the vertices of are isolated (no in- or out-edges), and there is an algorithm to list all non-isolated vertices in space and time.
We defer the proof to the full version of this paper.
3 Deciding Graph Connectivity
We state our first algorithm, which requires one register per vertex and timestep (but permits local revertibility).
Theorem 13.
There is a catalytic logspace algorithm that, given and a graph with vertices and edges and vertices , and -bit registers for and that are valid for modulus (Section 2.1), returns
Moreover, the algorithm runs in time , and is locally revertible in time , where is the maximum in-degree of .
Proof.
We first implicitly lift to a layered graph on vertices, defined as follows. We let the vertex set be , and the edge set be
For every vertex , let be the corresponding register with initial value .
We then describe the basic algorithm. For an edge , we let an edge push (resp. reverse edge push) be the update where we set
where the arithmetic operations are defined as in Section 2.1.
We let (resp. ) be the operation where we perform an edge push (resp. reverse edge push) on every edge from layer to layer . We do this by iterating over vertices , and using oracle queries to determine the in-neighbors of , and then pushing along these edges.
Finally, let be the operation where we set
For each , we define the push and reverse sequence
First, note that the catalytic tape is easy to reset:
Claim 14.
For every value and register , after executing we have that .
Proof.
It clearly suffices to prove that preserve the tape configuration. This follows directly from the linearity of addition and the definition of both operations. Finally, the difference in the final values at a register with is exactly the number of paths from to this register:
Lemma 15.
For every , let be the value of after . Then is exactly the number of length paths in , modulo .
Proof.
Note that is the value of after
since subsequent operations in do not write to .
Suppose the claim holds for every vertex in layer . Next, fix an arbitrary vertex , and let be the in-neighbors of in . Note that every length- path from to decomposes as
for some unique , so the paths are in one-to-one correspondence with length paths from to for some .
Finally, recall that has in-neighbors
and observe that
and hence
and so by the inductive hypothesis we are done. Then the final algorithm is straightforward. We determine and print . We compute this value by comparing the -bit registers bit by bit, each time using the sequence with alternating values of .
Lemma 16.
The algorithm runs in time.
Proof.
Given an edge and layer , pushing along this edge takes time , and hence a layer push takes time . Therefore executing and takes time . Finally, we invoke both routines times to compute the final value, so the total runtime is as claimed.
Finally, we show how the algorithm is locally revertible.
Lemma 17.
The algorithm is locally revertible in time .
Proof.
Suppose we receive a query to return , the initial value of the register . Let be the in-neighbors of , which we can enumerate over using the oracle for . The register is either in its initial state (in which case we can return its current value without modifying the tape), or some push sequence has been executed. In that case, the current value of is
where the second equality follows from the definition of , and the third follows from the fact that we do not modify registers in layer before reverting layer to the original register configuration. Thus, we can recover by enumerating over the in-neighbors of and computing
Afterwards, we revert to and continue execution as before. The time for the query is bounded by as claimed. This completes the proof of the desired properties.
Next, we present a version of the algorithm that avoids lifting the graph, at the cost of not permitting local revertibility. In this case, we do not compute the number of paths mod the register size, simply a number that is nonzero if a path exists.
Theorem 18.
For every and simple directed graph with vertices and edges and vertices , there is where:
-
, and
-
is nonzero if and only if there is an path in of length at most .
Moreover, there is a catalytic logspace algorithm that, given and a graph and vertices , and -bit registers for and that are valid for modulus , returns
Moreover, the algorithm runs in time .
Proof.
We describe the basic algorithm, which is like that of Theorem 13 but uses fewer registers. For each vertex , the two registers replace the registers from the previous algorithm.
We define layer push operations given a parity value . For in some fixed order (where we add dummy edges for every ), set
and then set . We define a reverse layer push as, for the same set of edges, setting and then
Next let be the operation where we set
For each , we initialize and define the push and reverse sequence:
By essentially the same argument as Claim 14, we have that after executing for , every register is reset to its initial configuration . The runtime is straightforward from the description.
Finally, we must prove correctness. For every , let be the parity of the registers pushed to in phase (and note that ).
Definition 19.
For every , vertex , and integer , define recursively as follows.
-
for all .
-
and for , .
-
For every ,
We prove that these values are exactly the register difference after the pushes:
Lemma 20.
Let be the value of after . For every we have
Proof.
For convenience, we define to be the initial value of for each vertex . We prove the lemma by induction.
For the base cases, we have that
Now assume this holds for and and consider the st push. WLOG suppose . For we have
and hence
Then a simple inductive argument proves that , and moreover that the set of for which is exactly those with an path of length at most .
Putting it all together
We then use these results to prove the main theorems.
For the deterministic algorithm, we choose the register size and modulus large enough so that the count of paths mod is equal to the count of paths. See 1
Proof.
We initialize registers each of size and set . Since we chose , all registers are valid no matter their initial configuration, so we immediately invoke Theorem 18 with . If the value obtained is nonzero, we return that there is a path, and otherwise return that there is no path. The runtime is immediate from the choice of and .
We now give the randomized algorithm. See 2
Proof.
Let .
The Algorithm.
For iterations (where the specific constant is to be chosen later), we proceed as follows. We initialize registers , each of size
We draw a random modulus and store in on the worktape. Let be the largest value such that (which we can compute in time and store on the worktape). We have that
Next, we draw a random shift and store it on the worktape. We add to each register with initial configuration and verify that is valid for . If not, we subtract from all registers and abort (and return ). Otherwise, we invoke Theorem 18 with this register set and . Let the returned value be . We first subtract from all registers. Then, if , we return that there is a path, and otherwise proceed to the next iteration. If we exhaust all iterations, we return that there is not a path.
Success Probability.
We first argue that the algorithm does not abort with high probability. There are registers, each of which we shift times. By Fact 10, the probability that any such shift results in an invalid configuration is at most , so a union bound completes the proof.
Next, note if , the algorithm clearly never returns there is a path. Otherwise, for each drawn by the algorithm, by Lemma 11 the probability that is at most , and hence choosing sufficiently large, we obtain that with probability at least there is some iteration where we detect a nonzero number of paths, and thus succeed.
Finally, runtime and space consumption follow directly from the description of the algorithm.
Finally, we finish the proof of the locally revertible algorithm. See 5
Proof.
We first modify the input graph by simulating access to the graph using the query oracle of Lemma 12. Let be the number of vertices of , let be the number of non-isolated vertices, let be its diameter, and recall that (after virtually adding a self-loop on ) it has maximum in-degree . Let be the logarithm of the bound on the number of paths in of Fact 8.
The Algorithm.
For iterations (where the specific constant is to be chosen later), we proceed as follows. First, we initialize the registers we will use by adding a random shift as described in Section 2.1. We will have a register corresponding to each layer and vertex in , indexed as
We allocate total registers on the catalytic tape corresponding to these vertices, but we only initialize the registers which corresond to non-isolated vertices of . (Recall Lemma 12 gives an algorithm for enumerating these vertices in time, amounting to time for layers.) Call a register relevant if it corresponds to where is a non-isolated vertex or .
Each register has size
We draw a random modulus and store in on the worktape. Let be the largest value such that (which we can compute in time and store on the worktape). We have that
Next, we draw a random shift and store it on the worktape. We add to each relevant register with initial configuration , and then verify that each is valid for . If not, we first subtract from all relevant registers, and then abort (and return ). Otherwise, we invoke Theorem 13 with
except we modify it to only push values from relevant registers. Let the returned value be . We restore the catalytic tape by subtracting from all relevant registers. Then, if , we return there is a path, and otherwise proceed to the next iteration. If we exhaust all iterations, we return that there is not a path.
Success Probability.
We first argue that the algorithm does not abort with high probability. Note that there are registers, each of which we shift times. By Fact 10, the probability that any such shift results in an invalid configuration is at most , so a union bound completes the proof.
Next, let be the total number of length- paths from to in the modified graph. If , the algorithm clearly never returns there is a path. Otherwise, for each drawn by the algorithm, by Lemma 11 the probability that is at most , and hence choosing sufficiently large, we obtain that with probability at least there is some iteration where we detect a nonzero number of paths, and thus succeed.
Finally, runtime and space consumption follow directly from the description of the algorithm.
Local Revertibility.
Finally, we argue that the algorithm is locally revertible. Given a query on register , we query the local revertibility routine of Theorem 13 on this register. Since we initialized the algorithm of Theorem 13 with in configuration , it returns this value, and we return by subtracting the stored shift . Finally, since has constant degree, the time is as claimed.
4 Estimating Random Walks
The bulk of our proof of Theorem 6 is a technique for simulating random walks on acyclic graphs:
Theorem 21 (random walk on a DAG).
There is an algorithm which, given a directed acyclic graph with vertices and edges, together with vertex , sink vertex , and parameter , returns such that
The algorithm runs in time . It uses workspace and catalytic space; the algorithm is guaranteed to restore the catalytic tape to its initial state as long as the input is valid – in particular, the graph has no cycles.
(This version of our algorithm has the curious property that it can be tricked into making irreversible changes to its catalytic tape if has cycles. If this is undesirable, the algorithm could be changed to require an efficiently checkable proof that is acyclic, like a topological ordering of its vertices.)
The algorithm is described by (Algorithm 1) and its subroutine (Algorithm 2). To prove Theorem 21, we must prove two things for every : in Section 4.2, we show that gives the correct output, and in Section 4.3, we show that it restores the catalytic tape at the end of the computation. Section 4.4 ties the proof together and analyzes the time and space used. Section 4.5 proves Theorem 6 by converting any graph into a larger acyclic graph, and then in Section 4.6, we explore what happens if we apply our technique directly to a graph with cycles, skipping the conversion step.
4.1 Registers
The algorithm uses one register on the catalytic tape for every vertex of the graph. We allocate bits to each register, where and is the number of simulations run by Algorithm 1. So, each register stores a number in the range . We choose this value of so that if we increment the value of a register times, each time adding one modulo , there is at most one time when it resets to instead of increasing by one. Concretely, this is used in the proof of Lemma 23 to bound the error introduced by this reset.
4.2 The output is correct
To evaluate how well simulates a random walk on , we will compare the number of times visits each vertex to the probability a true random walk would reach it. We will argue that for every vertex , the algorithm splits its time fairly over the different outgoing edges when it takes a step on line 11, from which it will follow that our simulation is sufficiently accurate.
Throughout this section, fix and . Fix an initial content of the catalytic tape , and let be the -bit register allocated to vertex with initial value .
Let as in .
The following definition establishes some notation to help reason about the accuracy of the simulation. It is illustrated in Figure 2.
Definition 22 (visit probability , visit count , error , transition count , transition error ).
Let be the probability that a random walk starting at reaches a vertex .
Let be the number of times visits during the forward phase of (lines 3–8). (A “visit” to the vertex stored in the variable occurs whenever evaluates the while loop condition on line 3.)
Define the error .
For , let be the number of those visits for which the variable had the given value on line 11 of (so unless is a sink). counts transitions where the algorithm followed the -th outgoing edge from .
Define the transition error .
Lemma 23.
For every vertex and , .
Proof.
Let us temporarily imagine the register always stores a value in , and that each time visits , line 6 increments it as instead of incrementing modulo . This causes the value to cycle through the values , so that on the -th visit to , , where is the starting value of from the catalytic tape. As a result, any two transition counts must differ by at most one:
| (1) |
In fact, cycles through the values . As a result cycles through the values in order, with one exception: if register cycles from to , then the cycle is interrupted. Since , this can happen at most once. So, instead of Equation 1, we have have that
Since , it follows that
and so
Lemma 24.
Let be all edges incoming to a vertex , where each is the -th outgoing edge from . Then .
Proof.
Using the facts that and , we have:
Lemma 25.
The final value returned by on line 12 is within additive error of the true visit probability .
Proof.
Let be the set of vertices of reachable from the start vertex , and let be a topological order on . That is, for any edge , appears before in the order.
For , consider the cut of with vertices on the left and on the right. We are interested in the total error over all the transitions which cross each such cut.
Let be the set of transitions which cross the cut. That is, a pair is in if is on the left of the cut and the -th outgoing edge from leads to a vertex on the right of the cut. See Figure 3.
Let : that is, is the number of edges that originate from the left side of the cut (whether or not they cross the cut).
Let , recalling from Definition 22 that ). We will show by induction that for all .
Base case: .
We know and , so and so by Lemma 23, .
Induction step: Fix and assume .
Let be the edges incoming to , where each is the -th outgoing edge from . Those are the transitions that contribute to but not , so we have . From Lemma 23, we have
and so applying Lemma 24 gives
completing the induction.
4.3 The catalytic tape is restored
restores its catalytic tape when it finishes. To see this, the following is enough:
Lemma 26.
Running then leaves all register values with the same values they started with.
Proof.
It is enough to show both calls to visit the same sequence of vertices, since then each register is incremented and decremented the same number of times. (We say “visits” vertex each time the loop condition on line 3 is evaluated.)
Loosely speaking, this is true because each time decides which outgoing edge to follow, it first (line 8) undoes the change made by , and so it ends up choosing the same edge index . This argument relies on the fact that a single run of never modifies the same register more than once, which follows from the fact that has no cycles.
To make this more precise, let be the vertices visited by , and be the vertices visited by the subsequent call to . We show by induction that for each , so that in particular the main loop ends at the same sink vertex in each case and so .
To begin with, . Now assume . If is a sink, both subroutine calls halt and we are finished. Otherwise, we must show the same value is chosen both times. Since neither subroutine call made any other changes to , when the second subroutine call subtracts one from on line 8, it exactly cancels out the only change made by the first subroutine call on line 6, and so the same value is recovered, and so the same next step is taken: .
Corollary 27.
leaves its catalytic tape unchanged.
Proof.
This is the same as saying the final values of all registers equal the initial values.
By induction on , we can see that calls to followed by calls to has no net effect on the registers . For this is clear. Lemma 26 provides the induction step. That is, calls to each can be decomposed as (1) calls to , then (2) a single call to each, which by Lemma 26 has no net effect, then (3) calls to . Since (2) has no effect, we are left with calls each, which by the induction hypothesis have no net effect.
4.4 Proof of Theorem 21 (random walk on a DAG)
Lemma 25 proves that gives a correct answer, and Corollary 27 proves that it restores its catalytic tape. The runtime is dominated by calls to , each of which visits each vertex of at most once. Visiting a vertex means executing one iteration of the main loop of , which takes time, so the total run time is .555It also uses time to count the number of edges in order to compute . Each register takes bits of the catalytic tape (Section 4.1), for a total of catalytic space The working memory only includes a constant number of variables , , etc, each taking working memory. ∎
4.5 Proof of Theorem 6 (random walk on a general graph)
For convenience, we restate the theorem here: See 6
Proof.
We construct an acyclic graph by creating copies of the input graph and arranging them in layers, with edges going from each layer to layer . That is, , and .
We then run (Algorithm 1) on the graph , using start vertex and sink vertex , and keeping the same parameter . Since a random walk on from to a sink is equivalent to a -step random walk on , the proof of Theorem 21 implies the algorithm will estimate the probability that a -step random walk ends at vertex witin the required additive error bound of . The same proof also implies our algorithm is catalytic.
The space bounds ( working space and catalytic space) follow directly from the proof of Theorem 21, since has vertices. The runtime is the time needed to run times. Each call to takes time, since every walk will have steps. So, the total runtime is .
4.6 What if we don’t eliminate cycles?
The proof of our algorithm’s correctness relies on the graph being acyclic, and so when we are given a general graph, we are forced to pay a penalty in space and time to convert it to an acyclic one. It is tempting to try avoiding the penalty by running the algorithm directly on a graph with cycles.
As it turns out, we end up with an algorithm that is not catalytic, but still accurately simulates a random walk, in the sense that it approaches the graph’s stationary distribution: see Theorem 29.
It would be interesting to try to modify this algorithm to be catalytic without incurring a time or space penalty. This seems challenging, because it is possible to construct a graph that causes to lose information that was stored on the catalytic tape: two different initializations of the registers lead to the same final register values, and so recovery is impossible. See Figure 4.
To describe the behaviour of this new algorithm, we first define four terms:
Definition 28 (probability vector, stochastic matrix, stationary distribution, mixing time).
A probability vector is any vector with nonnegative entries and . A matrix is (left) stochastic if every column is a probability vector. The stationary distribution of a stochastic matrix is any probability vector such that . We say mixes in time with error if the stationary distribution is unique and for every probability vector, . (Here, is the -th power of , not its transpose.)
We remark that our definition of mixing time implies the Markov chain is ergodic.
Theorem 29.
There is an algorithm which, given a graph with vertices and edges together with vertex and parameters , returns a number which approximates the stationary probability at in the following sense. If the random walk on has stationary distribution and mixes in time with accuracy , then
The algorithm runs in time and uses space .
We defer the proof to the full version of this paper.
5 Future Directions
We hope these examples will inspire others to find new efficient catalytic algorithms for these or other problems. In particular, it would be interesting to avoid the overhead in Theorem 6 from converting to an acyclic graph – Theorem 29 attempts this, but the algorithm fails to be catalytic. For connectivity, our algorithms are all incomparable (in speed, randomness, and revertibility). It would be interesting to obtain a best of both worlds result.
References
- [1] Greg Barnes, Jonathan F. Buss, Walter L. Ruzzo, and Baruch Schieber. A sublinear space, polynomial time algorithm for directed s-t connectivity. SIAM J. Comput., 27(5):1273–1282, 1998. doi:10.1137/S0097539793283151.
- [2] Harry Buhrman, Richard Cleve, Michal Koucký, Bruno Loff, and Florian Speelman. Computing with a full memory: catalytic space. In Proceedings of the Forty-Sixth Annual ACM Symposium on Theory of Computing, STOC ’14, pages 857–866, New York, NY, USA, 2014. Association for Computing Machinery. doi:10.1145/2591796.2591874.
- [3] Kuan Cheng and William M. Hoza. Hitting sets give two-sided derandomization of small space. Adv. Math. Commun., 18:1–32, 2022. doi:10.4086/TOC.2022.V018A021.
- [4] James Cook. How to borrow memory. https://www.falsifian.org/blog/2021/06/04/catalytic/.
- [5] James Cook, Jiatu Li, Ian Mertz, and Edward Pyne. The structure of catalytic space: Capturing randomness and time via compression. Electronic Colloquium on Computational Complexity: ECCC, 2024.
- [6] Dean Doron, Edward Pyne, and Roei Tell. Opening up the distinguisher: A hardness to randomness approach for BPL=L that uses properties of BPL. In Proceedings of the 56th Annual ACM Symposium on Theory of Computing, STOC 2024, pages 2039–2049, New York, NY, USA, 2024. Association for Computing Machinery. doi:10.1145/3618260.3649772.
- [7] Michal Koucký, Ian Mertz, Edward Pyne, and Sasha Sami. Collapsing catalytic classes. Electron. Colloquium Comput. Complex., TR25-019, 2025. URL: https://eccc.weizmann.ac.il/report/2025/019.
- [8] Ian Mertz. Reusing space: Techniques and open problems. Bulletin of EATCS, 141(3), 2023. URL: http://eatcs.org/beatcs/index.php/beatcs/article/view/780.
- [9] Noam Nisan. On read once vs. multiple access to randomness in logspace. Theoretical Computer Science, 107(1):135–144, 1993. doi:10.1016/0304-3975(93)90258-U.
- [10] Edward Pyne. Derandomizing Logspace with a Small Shared Hard Drive. In Rahul Santhanam, editor, 39th Computational Complexity Conference (CCC 2024), volume 300 of Leibniz International Proceedings in Informatics (LIPIcs), pages 4:1–4:20, Dagstuhl, Germany, 2024. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.CCC.2024.4.
- [11] Walter J. Savitch. Relationships between nondeterministic and deterministic tape complexities. Journal of Computer and System Sciences, 4:177–192, 1970. doi:10.1016/S0022-0000(70)80006-X.
