Abstract 1 Introduction 2 Preliminaries 3 Deciding Graph Connectivity 4 Estimating Random Walks 5 Future Directions References

Efficient Catalytic Graph Algorithms

James Cook ORCID Toronto, Canada Edward Pyne ORCID MIT, Cambridge, MA, USA
Abstract

We give fast, simple, and implementable catalytic logspace algorithms for two fundamental graph problems.

First, a randomized catalytic algorithm for st connectivity running in O~(nm) time, and a deterministic catalytic algorithm for the same running in O~(n3m) 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 O~(mT2/ε) time estimates the probability a T-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 n.

Keywords and phrases:
catalytic computing, graph algorithms, catalytic logspace
Funding:
Edward Pyne: Supported by NSF award CCF-2310818.
Copyright and License:
[Uncaptioned image] © James Cook and Edward Pyne; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Graph algorithms analysis
; Theory of computation Pseudorandomness and derandomization ; Theory of computation Complexity classes
Related Version:
Full Version: https://arxiv.org/abs/2509.06209
Acknowledgements:
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 Saraf

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 O(logn) and the catalytic tape has size poly(n), 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 st 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 𝖳𝖢1𝖢𝖫 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 st connectivity with an estimated runtime of Θ(n8), and catalytic tape size Θ(n3logn).

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 n vertices and m edges together with vertices s,t, decides whether there exists a path from s to t. The algorithm uses O(logn) workspace and O~(n2) catalytic space, and runs in time O~(n3m).

Next, we give a randomized algorithm that improves the runtime to O~(nm) and space usage to O~(n), only a factor of n in runtime from the linear-workspace BFS algorithm:

Theorem 2.

There is a randomized catalytic algorithm that, given a simple directed graph with n vertices and mn edges together with vertices s,t, decides whether there exists a path from s to t. The algorithm uses O(logn) workspace and O~(n) catalytic space, and runs in time O~(nm).

We remark that a randomized (one-sided error) catalytic algorithm always resets the catalytic tape no matter the random coins. If there is no st path, the algorithm always returns no, and if there is an st path returns yes with probability at least 1/2.

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 O(log2n) and superpolynomial time [11], or polynomial time and slightly sublinear space n/2logn [1]. Under the assumption there does not exist a randomized stconn algorithm that simultaneously uses n1ε space and polynomial time, the catalytic space usage of Theorem 2 is optimal up to subpolynomial factors.333A randomized catalytic logspace algorithm for st connectivity using n1ε catalytic space would imply a randomized n1ε space, polynomial-time algorithm for st 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 A is locally revertible in time t if at any point during the execution of A with initial tape τ, the algorithm can be paused and queried on an index i, and will return τi in time t (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 t=polylog(n):

Theorem 5.

There is a randomized catalytic algorithm that, given a simple directed graph with n vertices and mn edges together with vertices s,t, decides whether there exists a path from s to t. The algorithm uses O(logn) workspace and O~(n3) catalytic space, and runs in time O~(nm). Moreover, the algorithm is locally revertible in time polylog(n).

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 n vertices and mn edges, together with vertices s,t and parameters T𝐍,ε>0, returns ρ such that

|ρPr[T-step random walk from s ends at t]|ε.

The algorithm runs in time O~(mT2/ε) and uses O(log(mT/ε)) workspace and O~(nTlog(m/ε)) 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 m1+o(1).

If G 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 G=(V,E) on n vertices, determines if there exists a path from s to t. We virtually lift G to a layered graph on (n+1) layers with vertex set {0,,n}×V, where we place an edge from (i,u) to (i+1,v) if (u,v)E.

Next, for every vV and timestep i{0,,n}, allocate an =O~(n) bit register on the catalytic tape, which we denote R(i,v), and interpret the register as a number in 𝐙/2𝐙. Let the initial value of the register be τ(i,v).

We define an edge push as, for an edge ((i,u),(i+1,v)) in the lifted graph, setting

R(i+1,v)R(i+1,v)+R(i,u).

For each layer i=0,,n1 in sequence, we perform an edge push for every edge in the layer.

Let α(n,t) be the final value of R(n,t) 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 R(0,s) (i.e. the register of the start vertex in the first layer) by 1 and performing the same sequence of edge pushes; let the new final value of R(n,t) be α(n,t). We show via an inductive argument that α(n,t)α(n,t) is exactly the number of length-n paths from s to t, modulo 2 (and by adding a self-loop to t we can assume that if an st path exists, there exists an st path of length n). By repeatedly executing the edge push sequence and comparing α(n,t) to α(n,t) bit by bit, we determine whether their difference is nonzero – equivalently, whether there exists an st path.

Figure 1: Pushing values along edges to detect whether a +1 is propagated from s to t.

Improving the runtime with randomness

Unfortunately, since the number of paths from s to t can be exponential in n and we count the number of paths mod the register size, our deterministic algorithm must take the register size to be Ω(n), so pushing a single edge takes linear time. Moreover, we must compute the entire sequence of pushes Ω(/logn)=Ω~(n) times to compare α(n,t) to α(n,t). To avoid this slowdown, we use randomness. Instead of working mod 2 for =Ω(n), we pick a random small modulus q and work mod q. If the number of paths is nonzero, with reasonable probability we will have

α(n,t)α(n,t)0(modq)

from which the algorithm can infer that there is a path from s to t. In this way, we reduce the size of each register to O(logn) bits.

If q is not a power of two, not all strings of length will correspond to values mod q, 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 dq chosen so that 2dq is small, and then draw a random shift β[2] (which we record on the worktape) and add β to every register. With high probability over β, this ensures every register contains a value less than dq (and otherwise we abort).

Local revertibility

Next, we discuss how to achieve local revertibility. After performing all edge pushes onto a register Ra=(i+1,v), the current value of this register is exactly its original value τa plus

u:(u,v)ER(i1,u)

where R(i1,u) is the current value of the register in the previous layer. Thus, if we receive a query for the initial value τa of this register, we can iterate over the in-neighbors of v, subtract off the register values of the previous layer, and thus return τa. The time for this operation is essentially the product of the in-degree of v and register size. Since we have already reduced the register size to O(logn), 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 n2 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 n 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 G is acyclic and 2-outregular, with each vertex having a 0 edge and 1 edge. We will determine the probability that a random walk from s ends at t with additive error at most ε.

Allocate one bit of the catalytic tape for each vertex. For vertex v, denote this register Rv. Run K=2m/ε walks from s as follows. At vertex v, we take the edge labeled with the current value of Rv, then set Rv1Rv. In this way, if we examine walks reaching v over the course of the K walks, the next edges taken are 0,1,0,1, or 1,0,1,0,. 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 0 approximately as many times as it is given a 1, 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 2m of its expected value, regardless of the number of simulations. Thus after K simulations, we obtain additive error at most 2m/Kε.

 Remark 7.

Our runtime is linear in 1/ε, which is better than the 1/ε2 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 T times, every out-edge is visited T/d±1 times, whereas for a true random walk, we would expect a deviation on the order of T/d±T.

Finally, we must restore the catalytic tape. This is done by running the “reverse” of our K 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.

Figure 2: Top row: simulated random walks, using one bit of catalytic space per vertex (shown as or ) to alternate between random choices. Bottom row: a comparison to a true random walk, illustrating the parts of Definition 22: visit probabilities pv (left), visit cv and transition cvr counts (centre), and errors ev=|cv3pv|, evr=|cvr32pv| (right).

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 𝐍={0,1,2,} the natural numbers, and for n𝐍 we denote [n]={0,1,,n1} the natural numbers less than n.

For a vertex v in a directed graph, din(v) is the number of incoming and dout(v) is the number of outgoing edges.

We require a very weak bound on the number of paths in a graph:

Fact 8.

For an n-vertex graph (possibly with self-loops), the number of length-T paths between any two vertices is at most Pn=nT.

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 f:{0,1}{0,1} using T(n) time, S(n) workspace, and W(n) catalytic space if it works as follows. The machine is given read-only access to x, read-write access to S(|x|) bits of workspace, read-write access to a catalytic tape R of length W(|x|) 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 x and τ, we have that the machine halts in at most T(|x|) steps with f(x) 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 R1,R2, for doing arithmetic over some modulus q. If q is a power of two, this is straightforward: allocate logq bits per register. However, our faster randomized connectivity algorithms (Theorems 2 and 5) need to work with arbitrary moduli q, which creates a difficulty: if we allocate =logq bits of the catalytic tape to each register, some registers may start with values outside the range 0,,21.

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 logq, and treat the -bit string as an element of 𝐙/qd𝐙, where d=d(q,) is the largest value such that qd2. We say R is valid for (modulus) q if its initial value is less than qd, and otherwise we say R is invalid.

Our algorithm ensures its registers are valid by applying a shift to all registers simultaneously.

Fact 10.

For an -bit register R with initial configuration τ, over a uniformly random shift β[2], (τ+β)mod2 is valid for q with probability greater than 11/(d+1).

Each valid register can be decomposed as having value aq+b; to do arithmetic modulo q, we leave a fixed and only change the b part. It is easy to see these operations can be computed in simultaneous time O~() and space O(log), given q,d as input. For valid registers R,R over modulus q, we let RR±R 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 V2P be arbitrary. For a uniformly random r[P2], the probability that V0(modr) is at most 1O(1/logP).

Proof.

Note that V can have at most P distinct prime factors, and for every prime q that is not one of these factors we have that V0(modq). Moreover, a random element in [S] is prime with probability Ω(1/logS) by the Prime Number Theorem. Thus, if we consider the interval [P2], this interval contains at least P2/O(logP) primes, of which at most P divide V, so the probability that we draw a prime that does not divide V is at least

P2/O(logP)PP2=Ω(1/logP).

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 G if its vertex set is [n] for some n𝐍, and for any v[n] we can make the following queries:

  • InDegG(v) (resp. OutDegG(v)) returns the in-degree din(v) (resp. out-degree dout(v)).

  • InNbrG(v,i) (resp. OutNbrG(v,i)) returns the ith in-neighbor (resp. out-neighbor) of v, 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 G with n vertices and m edges, where every vertex has in-degree at most n, there is a simulation of an oracle for a graph G on n=O(n2) vertices with the following properties:

  • The simulation can answer queries in O(logn) space and O(logn) time, with the exception of OutNbrG queries.

  • The maximum in-degree is 2.

  • The diameter is O~(n).

  • For vertices s,t[n], there is an st path in G if and only if there is an st path in G. (We have [n][n], so integers s,t representing vertices of G also represent vertices of G.)

All but O(m) of the vertices of G are isolated (no in- or out-edges), and there is an algorithm to list all non-isolated vertices in O(logn) space and O~(m+n) 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 ,q,T𝐍 and a graph G with n vertices and m edges and vertices s,t, and -bit registers Ri,u for i{0,,T} and uV that are valid for modulus q (Section 2.1), returns

(#of st paths of length T)modq.

Moreover, the algorithm runs in time O~(2T(m+n)), and is locally revertible in time O~(dmax), where dmax is the maximum in-degree of G.

Proof.

We first implicitly lift G=(V,E) to a layered graph on (n+1)n vertices, defined as follows. We let the vertex set be {0,,n}×V, and the edge set be

E={((i,v),(j,u)):j=i+1 and (v,u)E}.

For every vertex a=(i,v), let Ra be the corresponding register with initial value τa.

We then describe the basic algorithm. For an edge a=(i,u),b=(i+1,v), we let an edge push (resp. reverse edge push) be the update where we set

RbRb+Ra(resp. RbRbRa)

where the arithmetic operations are defined as in Section 2.1.

We let layerPushi (resp. revLayerPushi) be the operation where we perform an edge push (resp. reverse edge push) on every edge from layer i to layer i+1. We do this by iterating over vertices v, and using InNbrG(v) oracle queries to determine the in-neighbors of v, and then pushing along these edges.

Finally, let incStart(b) be the operation where we set

R(0,s)R(0,s)+b.

For each b, we define the push and reverse sequence

𝒫b=(incStart(b),layerPush0,,layerPushT1)
b=(revLayerPushT1,,revLayerPush0,incStart(b)).

First, note that the catalytic tape is easy to reset:

Claim 14.

For every value b and register Ra, after executing (𝒫b,b) we have that Ra=τa.

Proof.

It clearly suffices to prove that layerPushi,revLayerPushi 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 b={0,1} is exactly the number of paths from s to this register:

Lemma 15.

For every i,v,b, let α(i,v),b be the value of R(i,v) after 𝒫b. Then α(i,v),1α(i,v),0 is exactly the number of length i sv paths in G, modulo q.

Proof.

Note that α(i,v),b is the value of R(i,v) after

incStart(b),layerPush0,,layerPushi1

since subsequent operations in 𝒫b do not write to R(i,v).

Suppose the claim holds for every vertex in layer i1. Next, fix an arbitrary vertex w=(i,v), and let (u1,,ur)[V] be the in-neighbors of v in G. Note that every length-i path from s to v decomposes as

(s,,uj)(uj,v)

for some unique uj, so the paths are in one-to-one correspondence with length i1 paths from s to uj for some j.

Finally, recall that w has in-neighbors

a1=(i1,u1),,ar=(i1,ur).

and observe that

αw,bτw+j[r]αaj,b(modq)

and hence

αw,1αw,0j[r](αaj,1αaj,0)(modq)

and so by the inductive hypothesis we are done. Then the final algorithm is straightforward. We determine and print α(n,t),1α(n,t),0(modq). We compute this value by comparing the -bit registers bit by bit, each time using the sequence 𝒫b,b with alternating values of b.

Lemma 16.

The algorithm runs in O~(2T(n+m)) time.

Proof.

Given an edge e and layer i, pushing along this edge takes time O~(), and hence a layer push takes time O~((m+n)). Therefore executing 𝒫b and b takes time O~(T(n+m)). 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 O~(dmax).

Proof.

Suppose we receive a query to return τa, the initial value of the register Ra=(i,v). Let u1,,ur be the in-neighbors of v, which we can enumerate over using the oracle for G. The register Ra is either in its initial state (in which case we can return its current value without modifying the tape), or some push sequence 𝒫b has been executed. In that case, the current value of Ra is

Ra =αa,b
=τa+j[r]α(i1,uj),b
=τa+j[r]R(i1,uj)

where the second equality follows from the definition of 𝒫b, and the third follows from the fact that we do not modify registers in layer i1 before reverting layer i to the original register configuration. Thus, we can recover τa by enumerating over the in-neighbors of v and computing

Raj[r]R(i1,uj)=τa.

Afterwards, we revert Ra to αa,b and continue execution as before. The time for the query is bounded by O~(r)=O~(dmax) 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 st paths mod the register size, simply a number that is nonzero if a path exists.

Theorem 18.

For every T𝐍 and simple directed graph G with n vertices and m edges and vertices s,t, there is ζG,s,t𝐍 where:

  • ζG,s,t(n+1)T, and

  • ζG,s,t is nonzero if and only if there is an st path in G of length at most T.

Moreover, there is a catalytic logspace algorithm that, given ,q,T𝐍 and a graph G and vertices s,t, and -bit registers Rσ,v for σ{0,1} and vV that are valid for modulus q, returns

ζG,s,tmodq.

Moreover, the algorithm runs in time O~(2T(n+m)).

Proof.

We describe the basic algorithm, which is like that of Theorem 13 but uses fewer registers. For each vertex v, the two registers R0,v,R1,v replace the T+1 registers Ri,v from the previous algorithm.

We define layer push operations given a parity value σ{0,1}. For (u,v)E in some fixed order (where we add dummy edges (u,u) for every u), set

R¬σ,vR¬σ,v+Rσ,u.

and then set σ¬σ. We define a reverse layer push as, for the same set of edges, setting σ¬σ and then

R¬σ,vR¬σ,vRσ,u.

Next let incStart(b) be the operation where we set

R0,sR0,s+b.

For each b, we initialize σ=0 and define the push and reverse sequence:

𝒫b=(incStart(b),layerPush(n)),b=(revLayerPush(n),incStart(b)).

By essentially the same argument as Claim 14, we have that after executing (𝒫b,b) for b{0,1}, every register Rσ,v is reset to its initial configuration τσ,v. The runtime is straightforward from the description.

Finally, we must prove correctness. For every i, let σi{0,1} be the parity of the registers pushed to in phase i (and note that σ0=0).

Definition 19.

For every σ{0,1}, vertex v, and integer i1, define ζ(σ,v),i recursively as follows.

  • ζ(1,v),1=0 for all v.

  • ζ(0,s),0=1 and for vs, ζ(0,v),0=0.

  • For every v,

    ζ(σi+1,v),i+1:=ζ(σi1,v),i1+u:(u,v)Eζ(σi,u),i.

We prove that these values are exactly the register difference after the pushes:

Lemma 20.

Let α(σi,v),i,b be the value of Rσi,v after incStart(b),layerPush(i). For every vV we have

α(σi,v),i,1α(σi,v),i,0ζ(σi,v),i(modq).
Proof.

For convenience, we define α(1,v),1,b to be the initial value of R1,v for each vertex v. We prove the lemma by induction.

For the base cases, we have that

α(1,v),1,1α(1,v),1,0=0=ζ(0,v),1
α(0,v),0,1α(0,v),0,0=𝕀[v=s]=ζ(0,v),0

Now assume this holds for i and i1 and consider the i+1st push. WLOG suppose σi+1=0. For vV we have

α(0,v),i+1,bα(0,v),i1,b+u:(u,v)Eα(1,u),i,b(modq)

and hence

α(0,v),i+1,1α(0,v),i+1,0ζ(0,v),i1+u:(u,v)Eζ(1,u),iζ(1,v),i+1(modq).

Then a simple inductive argument proves that ζ(σi,v),i(n+1)i, and moreover that the set of v for which ζ(σi,v),i>0 is exactly those v with an sv path of length at most i.

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 q large enough so that the count of paths mod q is equal to the count of paths. See 1

Proof.

We initialize 2n registers {Rσ,v}σ{0,1},vV each of size =log((n+1)n)+1 and set q=2. Since we chose q=2, all registers are valid no matter their initial configuration, so we immediately invoke Theorem 18 with T=n. 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 T.

We now give the randomized algorithm. See 2

Proof.

Let Bn=(n+1)n+1.

The Algorithm.

For I=O(logn) iterations (where the specific constant is to be chosen later), we proceed as follows. We initialize 2n registers {Rσ,v}σ{0,1},vV, each of size

=5logBn.

We draw a random modulus q[log2Bn] and store in on the worktape. Let d be the largest value such that qd2 (which we can compute in time polylog(n) and store on the worktape). We have that

d22q>n3

Next, we draw a random shift β[2] and store it on the worktape. We add β to each register Rσ,v with initial configuration τσ,v and verify that τσ,v+β is valid for q. If not, we subtract β from all registers and abort (and return ). Otherwise, we invoke Theorem 18 with this register set and T=n. Let the returned value be ζ. We first subtract β from all registers. Then, if ζ0, 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 2n registers, each of which we shift O(logn) times. By Fact 10, the probability that any such shift results in an invalid configuration is at most 2/n3, so a union bound completes the proof.

Next, note if ζG,s,t=0, the algorithm clearly never returns there is a path. Otherwise, for each q drawn by the algorithm, by Lemma 11 the probability that ζG,s,t0(modp) is at most (1O(1/loglogBn))=(11/O(logn)), and hence choosing I=O(logn) sufficiently large, we obtain that with probability at least 11/100 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 G by simulating access to the graph G using the query oracle of Lemma 12. Let n=O(n2) be the number of vertices of G, let n′′=O(m) be the number of non-isolated vertices, let T=O~(n) be its diameter, and recall that (after virtually adding a self-loop on t) it has maximum in-degree 3. Let pn=logPn be the logarithm of the bound on the number of paths in G of Fact 8.

The Algorithm.

For I=O(logn) 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 G, indexed as

(i,v){0,,T}×[n].

We allocate n3 total registers on the catalytic tape corresponding to these vertices, but we only initialize the Tn′′=O~(nm) registers which corresond to non-isolated vertices of G. (Recall Lemma 12 gives an algorithm for enumerating these vertices in O~(m+n) time, amounting to O~(n(m+n)) time for n layers.) Call a register relevant if it corresponds to (i,v) where v is a non-isolated vertex or v{s,t}.

Each register has size

=5logpn.

We draw a random modulus q[pn2] and store in on the worktape. Let d be the largest value such that qd2 (which we can compute in time polylog(n) and store on the worktape). We have that

d22qm32.

Next, we draw a random shift β[2] and store it on the worktape. We add β to each relevant register Ra with initial configuration τa, and then verify that each τa+β is valid for q. If not, we first subtract β from all relevant registers, and then abort (and return ). Otherwise, we invoke Theorem 13 with

G=G,T=T

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 α0, 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 O~(nm) registers, each of which we shift O(logn) times. By Fact 10, the probability that any such shift results in an invalid configuration is at most 4/m3, so a union bound completes the proof.

Next, let V be the total number of length-n paths from s to t in the modified graph. If V=0, the algorithm clearly never returns there is a path. Otherwise, for each q drawn by the algorithm, by Lemma 11 the probability that V0(modp) is at most (1O(1/logpn))=(11/O(logn)), and hence choosing I=O(logn) sufficiently large, we obtain that with probability at least 11/100 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 a, we query the local revertibility routine of Theorem 13 on this register. Since we initialized the algorithm of Theorem 13 with Ra in configuration τa+β, it returns this value, and we return τa by subtracting the stored shift β. Finally, since G 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 G with n vertices and m edges, together with vertex s, sink vertex t, and parameter ε>0, returns ρ such that

|ρPr[random walk from s reaches t]|ε.

The algorithm runs in time O~(nm/ε). It uses O(log(nm/ε)) workspace and O~(nlog(m/ε)) 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 G 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 G has cycles. If this is undesirable, the algorithm could be changed to require an efficiently checkable proof that G is acyclic, like a topological ordering of its vertices.)

The algorithm is described by walk (Algorithm 1) and its subroutine walk_once (Algorithm 2). To prove Theorem 21, we must prove two things for every G,s,t,ε: in Section 4.2, we show that walk(G,s,t,ε) 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 Rv on the catalytic tape for every vertex v of the graph. We allocate bits to each register, where =logK and K=2m/ε is the number of simulations run by Algorithm 1. So, each register stores a number in the range 0,,21. We choose this value of so that if we increment the value of a register K times, each time adding one modulo 2, there is at most one time when it resets to 0 instead of increasing by one. Concretely, this is used in the proof of Lemma 23 to bound the error introduced by this reset.

Algorithm 1 walk(G,s,t,ε). Parameters: graph G, source s, target t, accuracy ε.
Algorithm 2 walk_once(G,s,m). Parameters: graph G, source s, mode m{forward,reverse}. Returns a sink vertex of G. (This algorithm modifies the catalytic tape, so it is not a catalytic algorithm. However, the changes are reversible, so it can be used as a subroutine in a catalytic algorithm.)

4.2 The output is correct

To evaluate how well walk simulates a random walk on G, we will compare the number of times walk_once visits each vertex to the probability a true random walk would reach it. We will argue that for every vertex v, the algorithm splits its time fairly over the dout(v) 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 G,s,t and ε. Fix an initial content of the catalytic tape τ, and let Rv be the -bit register allocated to vertex v with initial value τv.

Let K=2m/ε as in walk.

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 pv, visit count cv, error ev, transition count cvr, transition error evr).

Let pv be the probability that a random walk starting at s reaches a vertex v.

Let cv be the number of times walk_once visits v during the forward phase of walk (lines 38). (A “visit” to the vertex stored in the variable v occurs whenever walk_once evaluates the while loop condition on line 3.)

Define the error ev=|cvKpv|.

For r[dout(v)], let cvr be the number of those visits for which the variable r had the given value on line 11 of walk_once (so cv=r=0dout(v)1cvr unless v is a sink). cvr counts transitions where the algorithm followed the r-th outgoing edge from v.

Define the transition error evr=|cvrKpv/dout(v)|.

Lemma 23.

For every vertex v and r[dout(v)], evr2+ev/dout(v).

Proof.

Let us temporarily imagine the register Rv always stores a value in [dout(v)], and that each time walk_once visits v, line 6 increments it as Rv(Rv+1)moddout(v) instead of incrementing modulo 2. This causes the value r to cycle through the values 0,,dout(v)1, so that on the t-th visit to v, r=(τv+t1)moddout(v), where τv is the starting value of Rv from the catalytic tape. As a result, any two transition counts must differ by at most one:

|cvrcvr|1 (pretending Rv[dout(v)]). (1)

In fact, Rv cycles through the values 0,,2. As a result r cycles through the values 0,,dout(v)1 in order, with one exception: if register Rv cycles from 21 to 0, then the cycle is interrupted. Since 2K, this can happen at most once. So, instead of Equation 1, we have have that

|cvrcvr|2.

Since cv=r=0dout(v)1cvr, it follows that

|cvrcvdout(v)|=|cvrr=0dout(v)1cvrdout(v)|1dout(v)r=0dout(v)1|cvrcvr|<2.

and so

evr=|cvrKpvdout(v)||cvrcvdout(v)|+|cvdout(v)Kpvdout(v)|<2+evdout(v).

Lemma 24.

Let (u1,v),,(ud,v) be all edges incoming to a vertex v, where each (ui,v) is the ri-th outgoing edge from ui. Then evi=1deuiri.

Proof.

Using the facts that cv=i=1dcuiri and pv=i=1dpui/dout(ui), we have:

ev=|cvKpv|=|i=1d(cuiriKpui/dout(ui))|i=1m|cuiriKpui/dout(ui)|=i=1deuiri

Lemma 25.

The final value nreach/K returned by walk on line 12 is within additive error ε of the true visit probability pt.

Proof.

We prove this from Lemmas 23 and 24 using an induction argument.

Let V be the set of vertices of G reachable from the start vertex s, and let v0=s,v1,,vn=t be a topological order on V. That is, for any edge (u,v), u appears before v in the order.

For i{0,1,,n1}, consider the cut of G with vertices v0,,vi on the left and vi+1,,vn on the right. We are interested in the total error over all the transitions which cross each such cut.

Let Fi{(v,r)vV,r[dout(v)]} be the set of transitions which cross the cut. That is, a pair (v,r) is in Fi if v is on the left of the cut and the r-th outgoing edge from v leads to a vertex on the right of the cut. See Figure 3.

Let Di=j=0idout(vj): that is, Di is the number of edges that originate from the left side of the cut (whether or not they cross the cut).

Let σi=(v,r)Fievr, recalling from Definition 22 that evr=|cvrKpv/dout(v)|). We will show by induction that σi2Di for all i.

Base case: 𝝈𝟎=𝒓=𝟎𝐝𝐨𝐮𝐭(𝒗𝟎)𝒆𝒗𝟎𝒓.

We know cv0=K and pv0=1, so ev0=0 and so by Lemma 23, σ02dout(v0).

Induction step: Fix 𝒊[𝒏𝟏] and assume 𝝈𝒊𝟐𝑫𝒊.

Let (vj1,vi+1),,(vjd,vi+1) be the edges incoming to vi+1, where each (vjk,vi+1) is the rk-th outgoing edge from vjk. Those are the transitions that contribute to σi but not σi+1, so we have σi+1=σi+r=0dout(vi+1)1evi+1rk=1devjkrk. From Lemma 23, we have

r=0dout(vi+1)1evi+1r2dout(vi+1)+evi+1,

and so applying Lemma 24 gives

σi+1σi+2dout(vi+1)+evi+1k=1devjkrkσi+2dout(vi+1)2Di+1

completing the induction.

Figure 3: Two steps in the induction argument in the proof of Lemma 25. On the left, i=2 and on the right, i=3. In each case, Fi consists of the edges that cross the dashed line, and σi is the sum of the errors on those edges.

In particular, σn12m. The corresponding set of edges Fn1 are exactly vertex t’s in-edges. Therefore, by Lemma 24, et is at most

(v,r)Fn1evr=σn12m

When walk reaches line 12, nreach=ct, and so the algorithm returns ct/K. This is within ε of pt because

|nreachKpt|=etK2m2m/εε.

4.3 The catalytic tape is restored

walk restores its catalytic tape when it finishes. To see this, the following is enough:

Lemma 26.

Running walk_once(G,s,t,forward) then walk_once(G,s,t,reverse) leaves all register values Rv with the same values they started with.

Proof.

It is enough to show both calls to walk_once visit the same sequence of vertices, since then each register is incremented and decremented the same number of times. (We say walk_once “visits” vertex v each time the loop condition on line 3 is evaluated.)

Loosely speaking, this is true because each time walk_once(G,s,reverse) decides which outgoing edge OutNbrG(v,r) to follow, it first (line 8) undoes the change made by walk_once(G,s,forward), and so it ends up choosing the same edge index r. This argument relies on the fact that a single run of walk_once never modifies the same register Rv more than once, which follows from the fact that G has no cycles.

To make this more precise, let v0,,vt be the vertices visited by walk_once(G,s,forward), and v0,,vt be the vertices visited by the subsequent call to walk_once(G,s,reverse). We show by induction that vi=vi for each i, so that in particular the main loop ends at the same sink vertex in each case and so t=t.

To begin with, v0=v0=s. Now assume vi=vi. If vi is a sink, both subroutine calls halt and we are finished. Otherwise, we must show the same value r is chosen both times. Since neither subroutine call made any other changes to Rv, when the second subroutine call subtracts one from Rv on line 8, it exactly cancels out the only change made by the first subroutine call on line 6, and so the same value r is recovered, and so the same next step is taken: vi+1=vi+1.

Corollary 27.

walk leaves its catalytic tape unchanged.

Proof.

This is the same as saying the final values of all registers Rv equal the initial values.

By induction on K, we can see that K calls to walk_once(G,s,forward) followed by K calls to walk_once(G,s,reverse) has no net effect on the registers Rv. For K=0 this is clear. Lemma 26 provides the induction step. That is, K+1 calls to each can be decomposed as (1) K calls to walk_once(G,s,forward), then (2) a single call to each, which by Lemma 26 has no net effect, then (3) K calls to walk_once(G,s,reverse). Since (2) has no effect, we are left with K 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 walk gives a correct answer, and Corollary 27 proves that it restores its catalytic tape. The runtime is dominated by 2K calls to walk_once, each of which visits each vertex of G at most once. Visiting a vertex means executing one iteration of the main loop of walk_once, which takes polylog(n+m) time, so the total run time is O~(nKpolylogm)=O~(nm/ε).555It also uses O~(npolylogm) time to count the number of edges m in order to compute K. Each register takes O()=O(log(m/ε)) bits of the catalytic tape (Section 4.1), for a total of O~(nlog(m/ε)) catalytic space The working memory only includes a constant number of variables nreach, v, etc, each taking O(log(nm/ε)) 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 G=(V,E) by creating T+1 copies of the input graph G=(V,E) and arranging them in layers, with edges going from each layer i to layer i+1. That is, V=[T+1]×V, and E={((i,u),(i+1,v))t[T],(u,v)E}.

We then run walk (Algorithm 1) on the graph G, using start vertex (0,s) and sink vertex (T,t), and keeping the same parameter ε. Since a random walk on G from s to a sink is equivalent to a T-step random walk on G, the proof of Theorem 21 implies the algorithm will estimate the probability that a T-step random walk ends at vertex t witin the required additive error bound of ε. The same proof also implies our algorithm is catalytic.

The space bounds (O(lognmT/ε) working space and O~(nTlog(m/ε)) catalytic space) follow directly from the proof of Theorem 21, since G has nT vertices. The runtime is the time needed to run walk_once K=O(mT/ε) times. Each call to walk_once takes O~(T) time, since every walk will have T steps. So, the total runtime is O~(mT2/ε).

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 walk_once to lose information that was stored on the catalytic tape: two different initializations of the registers Rv lead to the same final register values, and so recovery is impossible. See Figure 4.

Figure 4: An example showing why the algorithm of Theorem 29 can’t restore its register values, and so is not catalytic. Two runs of the algorithm for T=4 steps are shown. The first and third graphs show two different ways to initialize two of the catalytic registers, with , representing the possible values as in Figure 2. The second and fourth graphs show the resulting walks highlighted in blue, and the final values of those registers. The final register values are the same, so the algorithm cannot know which initial values to restore the registers to.

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 v𝐑n is any vector with nonnegative entries and |v|1=1. A matrix W𝐑n×n is (left) stochastic if every column is a probability vector. The stationary distribution of a stochastic matrix W𝐑n×n is any probability vector π such that Wπ=π. We say W mixes in time T with error ε if the stationary distribution π is unique and for every probability vector, |WTvπ|ε. (Here, WT is the T-th power of W, 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 G with n vertices and m edges together with vertex v and parameters T,δ𝐍, returns a number ρ which approximates the stationary probability at v in the following sense. If the random walk on G has stationary distribution π and mixes in time T with accuracy ε, then

|ρπ(v)|ε+δ.

The algorithm runs in time O~(Tm/δ) and uses space O~(n).

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.