Trading Determinism for Time in Space Bounded Computations

Vivek Anand T Kallampally, Raghunath Tewari

Introduction

Deciding reachability between a pair of vertices in a graph is an important computational problem from the perspective of space bounded computations. It is well known that reachability in directed graphs characterizes the complexity class nondeterministic logspace (\NL). For undirected graphs the problem was known to be hard for the class deterministic logspace (Ł) and in a breakthrough result Reingold showed that is contained in Ł as well [Rei08]. Several other restrictions of the reachability problem are known to characterize other variants of space bounded complexity classes [Ete97, Bar89, BLMS98].

Unambiguous computations are a restriction of general nondeterministic computations where the Turing machine has at most one accepting computation path on every input. In the space bounded domain, unambiguous logspace (in short \UL) is the class of languages for which there is a nondeterministic logspace bounded machine that has a unique accepting path for every input in the language and zero accepting path otherwise. \UL was first formally defined and studied in [BJLR91, AJ93]. In 2000 Reinhardt and Allender showed that the class \NL is contained in a non-uniform version of \UL [RA00]. In a subsequent work it was shown that under the hardness assumption that deterministic linear space has functions that cannot be computed by circuits of size 2ϵn2^{\epsilon n}, it can be shown that \NL=\UL\NL=\UL [ARZ99]. Although it is widely believed that \NL and \UL are the same unconditionally and in a uniform setting, the question still remains open.

Savitch’s Theorem states that reachability in directed graphs is in \DSPACE(log⁡2n)\DSPACE(\log^{2}n), however the algorithm requires quasipolynomial time [Sav70]. On the other hand standard graph traversal algorithms such as DFS and BFS can decide reachability in polynomial time (in fact linear time) but require linear space. Wigderson asked the question that can we solve reachability in O(n1−ϵ)\mathcal{O}(n^{1-\epsilon}) space and polynomial time simultaneously, for some ϵ>0\epsilon>0 [Wig92]. Barnes et. al. gave a partial answer to this question by giving a O(n/2log⁡n)\mathcal{O}(n/2^{\sqrt{\log n}}) space and polynomial time algorithm for the problem [BBRS92]. Although this bound has been improved for several subclasses such as planar graphs [INP+13], layered planar graphs [CT15], minor-free and bounded genus graphs [CPT+14], for general directed graphs (and hence for the class \NL) we still do not have a better deterministic space upper bound simultaneously with polynomial time.

In this paper we show that directed graph reachability can be decided by an unambiguous O(log⁡2n)\mathcal{O}(\log^{2}n) space algorithm that simultaneously requires only polynomial time. Thus we get an improvement in the time required by Savitch’s algorithm by sacrificing determinism. Formally, we show the following theorem.

For the remainder of this paper all graphs that we consider are directed graphs unless stated otherwise.

2 Min-uniqueness of Graphs

An important ingredient of our proof is the min-uniqueness property of graphs. A graph GG is said to be min-unique with respect to an edge weight function WW if the minimum weight path between every pair of vertices in GG is unique with respect to WW. This turns out to be an important property and has been studied in earlier papers [Wig94, GW96, RA00]. In fact, the fundamental component of Reinhardt and Allender’s paper is a \UL algorithm for testing whether a graph is min-unique and then deciding reachability in min-unique graphs in \UL [RA00]. They achieve this by proposing a double inductive counting technique which is a clever adaptation of the inductive counting technique of Immerman and Szelepcsényi [Imm88, Sze88]. As a result of Reinhardt and Allender’s algorithm, in order to show that reachability in a class of graphs can be decided in \UL, one only needs to design an efficient algorithm which takes as input a graph from this class and outputs an O(log⁡n)\mathcal{O}(\log n) bit weight function with respect to which the graph is min-unique. This technique was successfully used to show a \UL upper bound on the reachability problem in several natural subclasses of general graphs such as planar graphs [BTV07], graphs with polynomially many paths from the start vertex to every other vertex [PTV12], bounded genus graphs [DKTV11] and minor-free graphs [AGGT16]. For the latter two classes of graphs reachability was shown to be in \UL earlier as well by giving reductions to planar graphs [KV10, TW09]. Note that Reinhardt and Allender defines min-uniqueness for unweighted graphs where the minimum length path is unique, whereas we define it for weighted graphs where the minimum weight path is unique. However it can easily be seen that both these notions are equivalent.

3 Overview of the Proof

We prove Theorem 1 in two parts. We first show how to construct an O(log⁡2n)\mathcal{O}(\log^{2}n) bit weight function WW with respect to which the input graph GG becomes min-unique. Our construction of the weight function WW uses an iterative process to assign weights to the edges of GG. We start by considering a subgraph of GG having a fixed radius and construct an O(log⁡n)\mathcal{O}(\log n) bit weight function with respect to which this subgraph becomes min-unique. For this we first observe that there are polynomially many paths in such a subgraph and then use the prime based hashing scheme of Fredman, Komlós and Szemerédi [FKS84] to give distinct weights to all such paths. Thereafter, in each successive round of the algorithm, we construct a new weight function with respect to which a subgraph of double the radius of the previous round becomes min-unique and the new weight function has an additional O(log⁡n)\mathcal{O}(\log n) bits. Hence in O(log⁡n)\mathcal{O}(\log n) many rounds we get a weight function which has O(log⁡2n)\mathcal{O}(\log^{2}n) bits and with respect to which GG is min-unique. We show that this can be done by an unambiguous, polynomial time algorithm using O(log⁡2n)\mathcal{O}(\log^{2}n) space. This technique is similar to the isolating weight construction in [FGT16], but their construction is in \qNC.

We then show that given a graph GG and an O(log⁡2n)\mathcal{O}(\log^{2}n) bit weight function with respect to which GG is min-unique, reachability in GG can be decided by an unambiguous, polynomial time algorithm using O(log⁡2n)\mathcal{O}(\log^{2}n) space. Note that a straightforward application of Reinhardt and Allender’s algorithm will not give the desired bound. This is because “unfolding” a graph with O(log⁡2n)\mathcal{O}(\log^{2}n) bit weights will result in a quasipolynomially large graph. As a result we will not achieve a polynomial time bound. We tackle this problem by first observing that although there are 2O(log⁡2n)2^{\mathcal{O}(\log^{2}n)} many different weight values, the weight of a shortest path can only use polynomial number of distinct such values. Using this observation we give a modified version of Reinhardt and Allender’s algorithm that iterates over the “good” weight values and ignores the rest. This allows us to give a polynomial time bound.

The rest of the paper is organized as follows. In Section 2 we define the various notations and terminologies used in this paper. We also state prior results that we use in this paper. In Section 3 we give the proof of Theorem 1.

Preliminaries

Correspondingly we define the function ll which represents the minimum length of such paths as

A graph GwG_{w} is said to be min-unique for paths of length at most ii, if for any pair of vertices uu and vv, the shortest path from uu to vv with length at most ii, is unique. GwG_{w} is said to be min-unique if GwG_{w} is min unique for paths of arbitrary length. Define weight function

For a graph GwG_{w}, vertex uu in GG, length ii and weight value kk, we define the quantities cki(u)c_{k}^{i}(u) and Dki(u)D_{k}^{i}(u) as the number of vertices at a distance at most kk from uu, using paths of length at most ii and the sum of the distances to all such vertices respectively. Formally,

An unambiguous Turing machine is a nondeterministic Turing machine that has at most one accepting computation path on every input [Val76]. We shall consider unambiguous computations in the context of space bounded computations. \USPACE(s(n))\USPACE(s(n)) denotes the class of languages decided by an unambiguous machine using O(s(n))\mathcal{O}(s(n)) space. In particular, \UL=\USPACE(log⁡n)\UL=\USPACE(\log n). \TIUSP(t(n),s(n))\TIUSP(t(n),s(n)) denotes the class of languages decided by an unambiguous machine using O(s(n))\mathcal{O}(s(n)) space and O(t(n))\mathcal{O}(t(n)) time simultaneously. In particular, when t(n)t(n) is a polynomial, we define

For graphs having polynomially many paths, we use the well known hashing technique due to Fredman, Komlós and Szemerédi [FKS84] to compute a weight function that assigns distinct weights to all such paths. We state the result below in a form that will be useful for our purpose.

[FKS84, PTV12] For every constant cc there is a constant c′c^{\prime} so that for every set SS of nn bit integers with ∣S∣≤nc|S|\leq n^{c} there is a c′log⁡nc^{\prime}\log n bit prime number pp so that for all x≠y∈S, x≢y mod px\neq y\in S,\ x\not\equiv y\bmod{p}.

Henceforth we will refer to Theorem 2 as the FKS hashing lemma.

Min-unique Weight Assignment

Reinhardt and Allender [RA00] showed that for every nn there is a sequence of n2n^{2} O(log⁡n)\mathcal{O}(\log n) bit weight functions such that every graph GG on nn vertices is min-unique with respect to at least one of them. For each weight function they construct an unweighted graph (say GwG_{w}) by replacing every edge with a path of length equal to the weight of that edge. Since the weights are O(log⁡n)\mathcal{O}(\log n) bit values therefore GwG_{w} is polynomially large in nn. Next they show that using the double inductive counting technique one can check unambiguously using a logspace algorithm if GwG_{w} is min-unique, and if so then check if there is a path from ss to tt as well. They iterate over all weight functions until they obtain one with respect to which GwG_{w} is min-unique and use the corresponding graph GwG_{w} to check reachability. Since we use an O(log⁡2n)\mathcal{O}(\log^{2}n) bit weight function with respect to which the input graph is min-unique, we cannot construct an unweighted graph by replacing every edge with a directed path of length equal to the corresponding edge weight.

Theorem 3 shows how to construct the desired weight function.

There is a nondeterministic algorithm that takes as input a directed graph GG and outputs along a unique computation path, an O(log⁡2n)\mathcal{O}(\log^{2}n) bit weight function WW such that GWG_{W} is min-unique, while all other computation paths halt and reject. For any two vertices ss and tt the algorithm also checks whether there is a path from ss to tt in G. The algorithm uses O(log⁡2n)\mathcal{O}(\log^{2}n) space and runs in polynomial time.

Since directed graph reachability is complete for \NL, Theorem 1 follows from Theorem 3.

To prove Theorem 3 we design an algorithm that outputs the desired weight function. The formal description of the construction is given in Algorithm 1. The algorithm works in an iterative manner for log⁡n\log n number of rounds. Initially we consider all paths in GG of length at most ll where l=21l=2^{1}. The number of such paths is bounded by nln^{l} and therefore by the FKS hashing lemma there exist a c′log⁡nc^{\prime}\log n bit prime p1p_{1} such that with respect to the weight function W1:=w0 mod p1W_{1}:=w_{0}\bmod p_{1}, Gw1G_{w_{1}} is min-unique for paths of length at most ll. To find the right prime p1p_{1} we iterate over all c′log⁡nc^{\prime}\log n bit primes and use Lemma 7 to check whether Gw1G_{w_{1}} is min-unique for paths of length at most ll.

We prove this by induction on the number of rounds, say jj. Assume that GWj−1G_{W_{j-1}} is min-unique for paths of length at most 2j−12^{j-1}. In the jj-th round, the algorithm considers all paths of length at most 2j2^{j}. By applying Lemma 4 we get a weight function WjW_{j} from Wj−1W_{j-1} which uses O(j⋅log⁡n)\mathcal{O}(j\cdot\log n) bits and GWjG_{W_{j}} is min-unique for paths of length at most 2j2^{j}. Hence in log⁡n\log n many rounds we get a weight function W:=Wlog⁡nW:=W_{\log n} such that GWG_{W} is min-unique. Note that the inner repeat-until loop runs for at most nc′n^{c^{\prime}} iterations due to the FKS hashing lemma.

Let pjp_{j} be the prime used in the jj-th round of Algorithm 1. Define p′:=max⁡{pj∣j∈[log⁡n]}p^{\prime}:=\max\{p_{j}\mid j\in[\log n]\}. By the FKS hashing lemma p′p^{\prime} is bounded by a polynomial in nn, say nc′n^{c^{\prime}}. We set B:=nc′+2B:=n^{c^{\prime}+2}. This implies that for any weight function of the form w=w0 mod pjw=w_{0}\bmod p_{j} and any path PP in GG, w(P)<Bw(P)<B. Observe that with respect to the final weight function WW, for any path PP in GG, W(P)<BqW(P)<B^{q}.

In each round the size of WjW_{j} increases by O(log⁡n)\mathcal{O}(\log n) bits and after log⁡n\log n rounds Wlog⁡nW_{\log n} is an O(log⁡2n)\mathcal{O}(\log^{2}n) bit weight function. By Lemma 7 checking whether a graph is min-unique with respect to an O(log⁡2n)\mathcal{O}(\log^{2}n) bit weight function requires O(log⁡2n)\mathcal{O}(\log^{2}n) space. Thus the total space complexity of Algorithm 1 is O(log⁡2n)\mathcal{O}(\log^{2}n).

The FKS hashing lemma guarantees that in each round only a polynomial number of primes need to be tested to find a weight function which is min-unique for paths of length at most 2j2^{j}. By Lemma 7 checking whether a graph is min-unique for paths of length at most 2j2^{j} can be done in polynomial time. Thus each round runs in polynomial time. There are only log⁡n\log n many round and hence Algorithm 1 runs in polynomial time.

By Lemma 7, Algorithm 2 is a nondeterministic algorithm which outputs its answer along a unique computation path, while all other computation paths halt and reject. All other steps in Algorithm 1 are deterministic. This shows the unambiguity requirement of the theorem. ∎

There is a nondeterministic algorithm A\mathcal{A}, that takes as inputs (G,w)(G,w) where GG is a graph on nn vertices and ww is a kk bit weight function such that GwG_{w} is min-unique for paths of length at most ll. A\mathcal{A} outputs a (k+O(log⁡n))(k+\mathcal{O}(\log n)) bit weight function w′w^{\prime} such that Gw′G_{w^{\prime}} is min-unique for paths of length at most 2l2l, along a unique computation path while all other computation paths halt and reject. A\mathcal{A} uses O(k+O(log⁡n))\mathcal{O}(k+\mathcal{O}(\log n)) space and runs in polynomial time.

The encoding of the output weight function w′w^{\prime} is the concatenation of the kk bit representation of the input weight function ww and an O(log⁡n)\mathcal{O}(\log n) bit prime number pp. The output weight function w′w^{\prime} is calculated as w′:=B⋅w+w0 mod pw^{\prime}:=B\cdot w+w_{0}\bmod p, where BB is the number defined in Algorithm 1. Multiplication using BB is used just to left shift ww and make room for the new function w0 mod pw_{0}\bmod p.

Lemma 4 proves the correctness of each iteration of the outer for loop of Algorithm 1. Before proving the lemma, we will show that if GwG_{w} is min-unique for paths of length at most ll, then the number of minimum weight paths with respect to ww of length at most 2l2l is bounded by a polynomial independent of ll. Hence it allows us to use the FKS hashing lemma to isolate such paths.

Let GG be a graph with nn vertices and ww be a weight function such the graph GwG_{w} is min-unique for paths of length at most ll. Then for any pair of vertices uu and vv, ∣Pw2l(u,v)∣\left|\mathcal{P}_{w}^{2l}(u,v)\right| is at most nn.

Let PP be a shortest path from uu to vv in GwG_{w} with length at most 2l2l with center vertex xx. That is P∈Pw2l(u,v)P\in\mathcal{P}_{w}^{2l}(u,v). Let P1P_{1} and P2P_{2} be the subpaths from uu to xx and xx to vv. Since xx is the center of PP, P1P_{1} has length at most ll. Note that P1P_{1} is the unique shortest path of length at most ll from uu to xx in GwG_{w}. This is because if there exists another path of length at most ll with a smaller weight than P1P_{1} from uu to xx then replacing P1P_{1} with this path in PP will result in a path of length at most 2l2l from uu to vv with a lower weight than PP. But this cannot happen since PP is a shortest path from uu to vv.

There is only one shortest path of length at most 2l2l from uu to vv with xx as its center.

Assume there is another shortest path P′P^{\prime} of length at most 2l2l from uu to vv with xx as its center. Let P1′P_{1}^{\prime} be the subpath of P′P^{\prime} from uu to xx. Since xx is the center of P′P^{\prime}, P1′P^{\prime}_{1} is of length at most ll. Similar to P1P_{1}, P1′P^{\prime}_{1} is a shortest path of length at most ll from uu to xx. This means there are two shortest paths of length at most ll from uu to xx. This is a contradiction since GG is min-unique for paths of length at most ll. ∎

Therefore each vertex can be the center of at most one path of length at most 2l2l from uu to vv. Thus the total number of shortest paths of length at most 2l2l from uu to vv in GwG_{w} is at most nn. Hence ∣Pw2l(u,v)∣≤n\left|\mathcal{P}_{w}^{2l}(u,v)\right|\leq n. This completes the proof of Lemma 5. ∎

When we sum over all possible pairs of uu and vv, the total number of shortest paths of length at most 2l2l in GwG_{w} is at most n3n^{3}.

GwG_{w} is min-unique for paths of length at most ll. Therefore by Lemma 5 the number of shortest paths between all pairs of vertices with at most 2l2l edges in GG is at most n3n^{3}. Let S\mathcal{S} be the set of these n3n^{3} shortest paths. With respect to the weight function w0w_{0} (see Section 2) each element of S\mathcal{S} gets a distinct weight. So by using the FKS hashing lemma we get a constant c′c^{\prime} and a c′log⁡nc^{\prime}\log n bit prime number pp such that with respect to the weight function w^\widehat{w} such that w^:=w0 mod p\widehat{w}:=w_{0}\bmod p, each element of S\mathcal{S} gets a distinct weight. Moreover, in GG between any pair of vertices the shortest path in S\mathcal{S} is unique.

Let BB be the number as defined in Algorithm 1. Now consider the weight function w′:=B⋅w+w^w^{\prime}:=B\cdot w+\widehat{w}. Since ww is a kk bit weight function and w^\widehat{w} is an O(log⁡n)\mathcal{O}(\log n) bit weight function therefore w′w^{\prime} is a (k+O(log⁡n))(k+\mathcal{O}(\log n)) bit weight function. Clearly ww has higher precedence than w^\widehat{w} in w′w^{\prime}. So for any two paths P1P_{1} and P2P_{2} in GG , we have if w′(P1)<w′(P2)w^{\prime}(P_{1})<w^{\prime}(P_{2}) then either w(P1)<w(P2)w(P_{1})<w(P_{2}) or both the predicates w(P1)=w(P2)w(P_{1})=w(P_{2}) and w^(P1)<w^(P2)\widehat{w}(P_{1})<\widehat{w}(P_{2}) are true. Additionally if w′(P1)=w′(P2)w^{\prime}(P_{1})=w^{\prime}(P_{2}) then w(P1)=w(P2)w(P_{1})=w(P_{2}) and w^(P1)=w^(P2)\widehat{w}(P_{1})=\widehat{w}(P_{2}).

All the unique shortest paths of length at most 2l2l in GwG_{w}, will be unique shortest paths of length at most 2l2l in Gw′G_{w^{\prime}} also. If there are multiple shortest paths of length at most 2l2l from uu to vv in GwG_{w}, w^\widehat{w} gives a unique weight to each of these paths. So Gw′G_{w^{\prime}} is min-unique for paths of length at most 2l2l.

We can check whether a graph Gw′G_{w^{\prime}} is min-unique for paths of length at most 2l2l using Lemma 7. Since pp is an c′log⁡nc^{\prime}\log n bit prime number, we can iterate over all the c′log⁡nc^{\prime}\log n bit primes and find pp. ∎

2 Checking for min-uniqueness

The next lemma shows how to check whether GwG_{w} is min-unique for paths of length at most ll in an unambiguous manner.

There is a nondeterministic algorithm that takes as input a directed graph GG, a kk bit weight function ww and a length ii and outputs along a unique computation path whether or not the graph GwG_{w} is min-unique for paths of length at most ii, while all other computation paths halt and reject. The algorithm uses O(k+log⁡n)\mathcal{O}(k+\log n) space and runs in polynomial time.

For every vertex vv in the GwG_{w} we check whether there are two minimum weight paths of length at most ii to some other vertex in GG. Algorithm 2 gives a formal description of this process. The algorithm iterates over all shortest path weight values that can be achieved by some path of length at most ii.

In the kk-th stage of the algorithm it considers a ball of radius kk consisting of vertices which have a shortest path of weight at most kk from vv and length at most ii. cki(v)c_{k}^{i}(v) denotes the number of vertices in this ball and Dki(v)D_{k}^{i}(v) denotes the sum of the weights of the shortest paths to all such vertices. Initially k=0k=0, c0i(v)=1c_{0}^{i}(v)=1 (consisting of only the vertex vv) and D0i(v)=0D_{0}^{i}(v)=0.

A direct implementation of the double inductive counting technique of Reinhardt and Allender [RA00] does not work since this would imply that we cycle over all possible weight values, which we cannot afford. We bypass this hurdle by considering only the relevant weight values. We compute the immediate next shortest path weight value k′k^{\prime}, and use k′k^{\prime} as the weight value for the next stage of the algorithm. This computation is implemented in Algorithm 3). Lemma 8 proves the correctness of this process. Note that the number of shortest path weight values from a fixed vertex is bounded by the number of vertices in the graph. This ensure that the number of iterations of the inner repeat-until loop of Algorithm 2 is bounded by nn.

After we get the appropriate weight value k′k^{\prime}, we then compute the values of ck′i(v)c_{k^{\prime}}^{i}(v) and Dk′i(v)D_{k^{\prime}}^{i}(v) by using a technique similar to Reinhardt and Allender (implemented in Algorithm 4). Additionally we also maintain a shared flag value BAD.WEIGHT\mathsf{BAD.WEIGHT} between Algorithms 2 and 4, which is set to true\mathsf{true} if GwG_{w} is not min-unique for paths of length at most ii, else it is false\mathsf{false}.

Note that Algorithm 5 is the only algorithm where we use non-determinism. The algorithm is similar to the unambiguous subroutine of Reinhardt and Allender [RA00] with the only difference being that here we consider weight of a path instead of length of a path. The algorithm assumes that the subgraph induced by all the paths of length at most ii and weight at most kk from uu is min-unique.

As a corollary of Theorem 1 we get the following result.

For s(n)≥log⁡ns(n)\geq\log n, \NSPACE(s(n))⊆\TIUSP(2O(s(n)),s2(n))\NSPACE(s(n))\subseteq\TIUSP(2^{\mathcal{O}(s(n))},s^{2}(n)).

References