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 , it can be shown that [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 , 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 space and polynomial time simultaneously, for some [Wig92]. Barnes et. al. gave a partial answer to this question by giving a 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 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 is said to be min-unique with respect to an edge weight function if the minimum weight path between every pair of vertices in is unique with respect to . 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 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 bit weight function with respect to which the input graph becomes min-unique. Our construction of the weight function uses an iterative process to assign weights to the edges of . We start by considering a subgraph of having a fixed radius and construct an 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 bits. Hence in many rounds we get a weight function which has bits and with respect to which is min-unique. We show that this can be done by an unambiguous, polynomial time algorithm using 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 and an bit weight function with respect to which is min-unique, reachability in can be decided by an unambiguous, polynomial time algorithm using 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 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 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 which represents the minimum length of such paths as
A graph is said to be min-unique for paths of length at most , if for any pair of vertices and , the shortest path from to with length at most , is unique. is said to be min-unique if is min unique for paths of arbitrary length. Define weight function
For a graph , vertex in , length and weight value , we define the quantities and as the number of vertices at a distance at most from , using paths of length at most 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. denotes the class of languages decided by an unambiguous machine using space. In particular, . denotes the class of languages decided by an unambiguous machine using space and time simultaneously. In particular, when 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 there is a constant so that for every set of bit integers with there is a bit prime number so that for all .
Henceforth we will refer to Theorem 2 as the FKS hashing lemma.
Min-unique Weight Assignment
Reinhardt and Allender [RA00] showed that for every there is a sequence of bit weight functions such that every graph on vertices is min-unique with respect to at least one of them. For each weight function they construct an unweighted graph (say ) by replacing every edge with a path of length equal to the weight of that edge. Since the weights are bit values therefore is polynomially large in . Next they show that using the double inductive counting technique one can check unambiguously using a logspace algorithm if is min-unique, and if so then check if there is a path from to as well. They iterate over all weight functions until they obtain one with respect to which is min-unique and use the corresponding graph to check reachability. Since we use an 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 and outputs along a unique computation path, an bit weight function such that is min-unique, while all other computation paths halt and reject. For any two vertices and the algorithm also checks whether there is a path from to in G. The algorithm uses 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 number of rounds. Initially we consider all paths in of length at most where . The number of such paths is bounded by and therefore by the FKS hashing lemma there exist a bit prime such that with respect to the weight function , is min-unique for paths of length at most . To find the right prime we iterate over all bit primes and use Lemma 7 to check whether is min-unique for paths of length at most .
We prove this by induction on the number of rounds, say . Assume that is min-unique for paths of length at most . In the -th round, the algorithm considers all paths of length at most . By applying Lemma 4 we get a weight function from which uses bits and is min-unique for paths of length at most . Hence in many rounds we get a weight function such that is min-unique. Note that the inner repeat-until loop runs for at most iterations due to the FKS hashing lemma.
Let be the prime used in the -th round of Algorithm 1. Define . By the FKS hashing lemma is bounded by a polynomial in , say . We set . This implies that for any weight function of the form and any path in , . Observe that with respect to the final weight function , for any path in , .
In each round the size of increases by bits and after rounds is an bit weight function. By Lemma 7 checking whether a graph is min-unique with respect to an bit weight function requires space. Thus the total space complexity of Algorithm 1 is .
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 . By Lemma 7 checking whether a graph is min-unique for paths of length at most can be done in polynomial time. Thus each round runs in polynomial time. There are only 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 , that takes as inputs where is a graph on vertices and is a bit weight function such that is min-unique for paths of length at most . outputs a bit weight function such that is min-unique for paths of length at most , along a unique computation path while all other computation paths halt and reject. uses space and runs in polynomial time.
The encoding of the output weight function is the concatenation of the bit representation of the input weight function and an bit prime number . The output weight function is calculated as , where is the number defined in Algorithm 1. Multiplication using is used just to left shift and make room for the new function .
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 is min-unique for paths of length at most , then the number of minimum weight paths with respect to of length at most is bounded by a polynomial independent of . Hence it allows us to use the FKS hashing lemma to isolate such paths.
Let be a graph with vertices and be a weight function such the graph is min-unique for paths of length at most . Then for any pair of vertices and , is at most .
Let be a shortest path from to in with length at most with center vertex . That is . Let and be the subpaths from to and to . Since is the center of , has length at most . Note that is the unique shortest path of length at most from to in . This is because if there exists another path of length at most with a smaller weight than from to then replacing with this path in will result in a path of length at most from to with a lower weight than . But this cannot happen since is a shortest path from to .
There is only one shortest path of length at most from to with as its center.
Assume there is another shortest path of length at most from to with as its center. Let be the subpath of from to . Since is the center of , is of length at most . Similar to , is a shortest path of length at most from to . This means there are two shortest paths of length at most from to . This is a contradiction since is min-unique for paths of length at most . ∎
Therefore each vertex can be the center of at most one path of length at most from to . Thus the total number of shortest paths of length at most from to in is at most . Hence . This completes the proof of Lemma 5. ∎
When we sum over all possible pairs of and , the total number of shortest paths of length at most in is at most .
is min-unique for paths of length at most . Therefore by Lemma 5 the number of shortest paths between all pairs of vertices with at most edges in is at most . Let be the set of these shortest paths. With respect to the weight function (see Section 2) each element of gets a distinct weight. So by using the FKS hashing lemma we get a constant and a bit prime number such that with respect to the weight function such that , each element of gets a distinct weight. Moreover, in between any pair of vertices the shortest path in is unique.
Let be the number as defined in Algorithm 1. Now consider the weight function . Since is a bit weight function and is an bit weight function therefore is a bit weight function. Clearly has higher precedence than in . So for any two paths and in , we have if then either or both the predicates and are true. Additionally if then and .
All the unique shortest paths of length at most in , will be unique shortest paths of length at most in also. If there are multiple shortest paths of length at most from to in , gives a unique weight to each of these paths. So is min-unique for paths of length at most .
We can check whether a graph is min-unique for paths of length at most using Lemma 7. Since is an bit prime number, we can iterate over all the bit primes and find . ∎
2 Checking for min-uniqueness
The next lemma shows how to check whether is min-unique for paths of length at most in an unambiguous manner.
There is a nondeterministic algorithm that takes as input a directed graph , a bit weight function and a length and outputs along a unique computation path whether or not the graph is min-unique for paths of length at most , while all other computation paths halt and reject. The algorithm uses space and runs in polynomial time.
For every vertex in the we check whether there are two minimum weight paths of length at most to some other vertex in . 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 .
In the -th stage of the algorithm it considers a ball of radius consisting of vertices which have a shortest path of weight at most from and length at most . denotes the number of vertices in this ball and denotes the sum of the weights of the shortest paths to all such vertices. Initially , (consisting of only the vertex ) and .
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 , and use 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 .
After we get the appropriate weight value , we then compute the values of and by using a technique similar to Reinhardt and Allender (implemented in Algorithm 4). Additionally we also maintain a shared flag value between Algorithms 2 and 4, which is set to if is not min-unique for paths of length at most , else it is .
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 and weight at most from is min-unique.
As a corollary of Theorem 1 we get the following result.
For , .