Abstract
In this paper we study graph problems in the dynamic streaming model, where the input is defined by a sequence of edge insertions and deletions. As many natural problems require space, where n is the number of vertices, existing works mainly focused on designing space algorithms. Although sublinear in the number of edges for dense graphs, it could still be too large for many applications (e.g., n is huge or the graph is sparse). In this work, we give single-pass algorithms beating this space barrier for two classes of problems. We present o(n) space algorithms for estimating the number of connected components with additive error of a general graph and -approximating the weight of the minimum spanning tree of a connected graph with bounded edge weights, for any small constant . The latter improves upon the previous space algorithm given by Ahn et al. (SODA 2012) for the same class of graphs. We initiate the study of approximate graph property testing in the dynamic streaming model, where we want to distinguish graphs satisfying the property from graphs that are -far from having the property. We consider the problem of testing k-edge connectivity, k-vertex connectivity, cycle-freeness and bipartiteness (of planar graphs), for which, we provide algorithms using roughly space, which is o(n) for any constant . To complement our algorithms, we present space lower bounds for these problems, which show that such a dependence on is necessary.
Keywords: Dynamic graph streams, Graph sketching, Property testing, Minimum spanning tree
Introduction
Graphs or networks are a natural way to describe structural information. For example, users of Facebook and the acquaintance relations among them form a social network, the proteins together with interactions between them define a biological network, and web-pages and hyperlinks give rise to a huge web graph. Due to the rapid development of information technology, many such graphs become extremely large, and are constantly changing, which poses great challenges for analyzing their structures. Over the last decade, the data stream model [34] has proven to be successful in dealing with big data. In this model, the algorithm should make only one pass (or a few passes) over the stream, and use sublinear working space. The time required to output the final answer and process each element is also important. There is a growing body of work studying graph problems over data streams. Graph streams were first considered by Henzinger et al. [24], and later have been extensively studied in the insertion-only model (eg., [17, 18, 34]), where there is no edge deletion in the stream. Recently, starting from the seminal works of Ahn, Guha and McGregor [2, 3], the interest has shifted to the dynamic streaming model, where the edges can be both inserted and deleted (see eg., [1, 5–7, 9, 10, 14, 23, 28, 29, 31, 33]). In this setting, most algorithms designed are linear sketch-based, which is also an effective technique for processing distributed graphs. For more information about graph streaming algorithms see the recent survey by McGregor [32].
For graph streams, both insertion-only and dynamic, the research in the past has mostly focused on the semi-streaming model, in which the algorithms are allowed to use space, where n is the number vertices in the graph. (For notational convenience, we will use and to hide factors.) The reason behind this is that even in the insertion-only model, many natural graph problems require space (e.g., testing if the graph is connected [18]). Note that the allowed space in semi-streaming model is sublinear in the input size as the number of edges of the graph might be as large as . However, in many real applications (e.g., the input graph is already very sparse), an space algorithm might be even worse than just storing all the edges. From this perspective, one may naturally ask the question which kind of problems can be solved with even less space, i.e., o(n) space.
To the best of our knowledge, very few results are known in this direction. Chitnis et al. [10] and Fafianie and Kratsch [16] introduced parameterized graph stream algorithms which may only use o(n) space with some promise of the size of the solution. This parameterized setting has been further investigated in [9]. In addition, it has been shown that the size of the maximum matching can be approximated within constant factor in space for graphs with bounded arboricity [7, 9, 15].
In this paper, we study two classes of graph problems that admit single-pass o(n) space algorithms in the dynamic streaming model. The first class contains the problems of estimating the number of connected components and the weight of the minimum spanning tree (MST). We show that one can estimate the number of connected components within an additive error of with o(n) space and post-processing time, for any constant . We also present an algorithm to -approximate the weight of the MST with o(n) space and post-processing time for connected graphs with bounded edge weights, which improves the best known algorithm with space in the same setting given by Ahn et al. [2]. It is worth noting that the problem of estimating the number of connected components within small multiplicative error requires space, as it is generally harder than the problem of (exactly) testing graph connectivity; and that estimating the weight of MST for graphs with arbitrarily large edge weights (e.g., ) requires space (see Theorem 10). Previously these two problems have been studied in the framework of sublinear time algorithms (see eg. [8, 40]).
The second class consists of problems that are relaxations of deciding graph properties. Given a huge graph, it is very useful to know whether the graph has some predetermined property, such as k-connectivity, bipartiteness, cycle-freeness and etc., which provide valuable information about the graph. However, besides the requirement of space, exactly testing properties sometimes is too strong a requirement for analyzing highly dynamic graphs, since the answer may change in the next second due to an insertion or deletion of a single edge. In this paper, we initiate the study of approximate graph property testing in the dynamic streaming model: we want to test whether a graph satisfies some property or one has to modify a small constant fraction of edges to make it have the property. This notion of approximation is adapted from the framework of property testing [21, 22, 36], and a large number of existing literatures have given efficient testing algorithms (called testers) for many properties under different query models (see surveys [20, 39]). We show that some fundamental properties can be tested in both o(n) space and post-processing time in the dynamic streaming model and we also present close lower bounds for these problems which hold even in the insertion-only model. We remark that McGregor [32] also suggested to study the (approximate) property testers in graph streaming model, and asked whether more space-efficient algorithms exist for these problems, and we thus give an affirmative answer to this question.
Our Results
Now we formally state our main results. Our results regarding estimating the number of connected components and the MST weight are as follows.
Estimating the Number of Connected Components We present a dynamic streaming algorithm that estimates the number of connected components within additive error in space and post-processing time for any constant . We note that a lower bound of for this problem follows from the work [42].
Estimating the Weight of the Minimum Spanning Tree (MST) In this problem, we want to estimate the weight of the MST of a connected graph with edge weights in the set . We give a dynamic streaming algorithm that computes a -approximation of the MST weight and uses space and post-processing time for any constant . By an argument in [8], the result can be extended to non-integral weights, as long as the ratio between the largest and the smallest weight is bounded. A space lower bound of is shown for this problem.
We also present approximate testing algorithms for a number of fundamental graph properties. Before stating the performance of these algorithms, we first introduce some definitions. Given a graph property , an m-edge graph G is called -far from having if one has to modify more than edges of G to get a graph satisfying . This distance definition is adapted from [36] and is most suitable for general graphs where neither edge density nor maximum degree is restricted. We call an algorithm a (dynamic) streaming tester for , if it makes a single-pass over a stream of edge insertions and deletions, with probability at least 2 / 3, accepts any graph satisfying , and rejects any graph that is -far from having .
We give sketch-based streaming testers for properties of being connected, k-edge connected, k-vertex connected, cycle-freeness and bipartite (for planar graphs). The performance of our testers are summarized in Table 1. We stress that most of our testers have (asymptotically) the same post-processing time as the space they used except for testing k-edge connectivity when and k-vertex connectivity when .
Table 1.
Upper and lower bounds of streaming testers
| Space | Space lower bound | |
|---|---|---|
| Connectivity | ||
| k-Edge connectivity | ||
| k-Vertex connectivity | ||
| Cycle-freeness | ||
| Bipartiteness of planar graphs |
Our Techniques
To estimate the number of connected components with small additive error , we note that it is sufficient to estimate the number of connected components of small size (i.e., ), since the number of components of size larger than this is at most (see also [8]). To estimate , the following vertex sampling framework is used: we sample a sufficiently large set of vertices S by sampling each vertex in G with some probability p, and then use the statistics of the sampled connected components of the original graph to estimate . For any small connected component C in G, it is likely that all the vertices in C will be sampled out. Conditioned on this, we add to our final estimator, which is the reciprocal of the probability that C is entirely sampled out. Now the task is then to identify which subsets of S are connected components in the original graph. A trivial way is to check all subsets of S, which takes too much time. A more efficient way is to only check all the connected components in G[S], since a sampled component of G must also form a component in G[S]. We carefully use a set of linear sketches to do this. More specifically, we first recover all connected components in G[S] by invoking a sketch-based streaming algorithm given in [2], which only needs space near-linear in |S|. Then we use (different) linear sketches to check if any of these components is indeed a connected component of the original graph. We remark that the first set of linear sketches of a vertex v sketch its neighborhood information in G[S], while the second set sketch its neighborhood information in G. Our o(n) space streaming algorithm for -approximating the weight of MST follows via a connection between the number of connected components and the weight of MST established in [8].
To give testers for some graph property in dynamic streaming model, we start from the observation that if a graph G is far from having , then typically, there exist many small disjoint subgraphs, each of which is a witness that the graph G does not satisfy . (For example, if is connectivity, then there exists at least connected components of size at most in a graph that is -far from being connected.) This implies that by sampling a sufficient large set of vertices, with high probability, one of such subgraphs will be entirely sampled. Checking which vertices form a witness of the original graph can then be done by using the aforementioned framework. Different sketches will be used for testing different properties.
To prove lower bounds for our studied problems, we give reductions from Boolen Hidden Hypermatching (BHH) problem that was studied in [42]. Our reductions share similarity with the reduction in [42] to the cycle-counting problem and the reductions in [27, 30] to the approximate max-cut problem.
Related Work
Ahn et al. [2] initiated the study of graph sketches, and gave dynamic semi-streaming algorithms for computing a spanning forest (which can be used to count the exact number of connected components), and -approximate the weight of MST. They also proposed algorithms to exactly testing of a set of properties, including testing connectivity, k-edge connectivity, and bipartiteness. Recently, Guha et al. gave dynamic streaming algorithms for exactly testing of k-vertex connectivity [23]. All these algorithms use space ( for k-connectivity). On the other hand, the randomized space lower bounds for these exact testing problems were known to be in the insertion-only model [17, 18]. Recently, Sun and Woodruff improved these lower bounds to [41]. Verbin and Yu [42] proved a lower bound for cycle-counting, which implied a lower bound of for estimating the number of components.
In the random order insertion-only model Kapralov et al. [26] gave a one pass streaming algorithm that estimates the maximum matching size with polylogarithmic approximation ratio in polylogarithmic space. Although sublinear in n, the model considered is very different from ours.
Sublinear time algorithms for estimating the number of connected component and the weight of MST were first given by Chazelle et al. [8]. Later these two problems have been further considered in geometric settings [11, 13, 19]. In particular, Frahling et al. studied the problem of -approximating the weight of MST in dynamic geometric data stream [19].
There has been a rich line of work on graph property testing in the query model (see surveys [20, 39]) and the goal there is to design fast algorithms that make as few queries as possible. The query models that are mostly related to ours are bounded degree model and general graph model. In particular, our definition of -far is adapted from the general graph model. Goldreich and Ron [22] initiated the study of property testers in bounded degree graph model, and gave testers for connectivity, k-edge connectivity, 2, 3-vertex connectivity, cycle-freeness, Eulerianity. Testing k-vertex connectivity in bounded degree graphs for arbitrary constant k was given in [43]. These testers have later been generalized to general graph model [35, 36]. Testing bipartiteness in planar graphs was studied in [12].
After having submitted the paper, we became aware that Hossein Jowhari [25] has independently studied the problem of estimating the number of connected components and provided similar results as ours, while he did not consider the streaming property testers considered here. Furthermore, subsequent to our work, Peng and Sohler [37] showed that in random order streams, approximating the number of connected components with additive error and -approximating the weight of the MST of a connected graph with bounded edge weights can be solved in a single-pass and constant space (in terms of words), i.e., the space complexity only depends on and is independent of the size of the graph.
Preliminaries
Notations
Let . We use to denote the vertex set of the graph G defined by the stream, and let m denote the number of edges of G. For an undirected graph and a vertex , we let denote all the neighbors of i. For a set , let denote the set of vertices in that have at least one neighbor in C, that is, . Let denote the set of edges crossing C and . We will use G[C] to denote the subgraph induced by C.
For each vertex i, we define two vectors and to encode the neighborhood information of i as follows:
By simple induction arguments, it is easy to prove that for any vertex set , the nonzero entries in the vector corresponds to the edges between C and its complement . The nonzero entries in corresponds exactly to vertices in .
Linear Sketches
Linear sketch (or sketch for short) is a powerful tool widely used in the streaming model and other areas. Given a large vector , we want to construct a small sketch , from which certain properties of can be recovered. We call a linear sketch if for all , and this additive property make it trivial to implement linear sketches in the dynamic streaming model. As in the previous works, we will use linear sketches as our main tool.
AGM sketch We will use a dynamic streaming algorithm for constructing a spanning forest of a graph by Ahn, Guha and McGregor [2], which is summarized as follows.
Theorem 1
(AGM sketch [2]) There exists a single-pass sketch-based dynamic streaming algorithm that uses space, and recovers a spanning forest of the graph with probability 0.99. The recovery time of the algorithm is , and the update time is .
AMS sketch To check whether the input vector is or not, one can simply maintain a constant approximation of its second frequency moment, that is . In particular, by using the classical AMS sketch that was introduced by Alon, Matias and Szegedy [4], one can approximate within a multiplicative factor of c using bits of memory with probability at least , for any and constant .
Exactk-sparse recovery We call a vector k-sparse if . Given a non-zero vector , the goal here is to recover if is k-sparse, otherwise outputs Fail. We have the following result from [38].
Lemma 1
[38] There exists an space sketch-based algorithm that takes as input a non-zero vector , and with probability , recovers if is k-sparse, otherwise outputs Fail. The update time is and the recovery time is .
Estimating the Number of Connected Components and MST Weight
In this section, we present and analyze our algorithms for estimating the number of the connected components in a graph and -approximating the weight of the MST.
Estimating the Number of Connected Components
Our first observation is that, to estimate the number of connected components within additive error , we can simply ignore all the large components (see also [8]). In particular, the number of components of size larger than is at most . Thus it will be sufficient to estimate the number of components of small size, for which we have the following theorem.
Theorem 2
For any constant , there exists a one-pass dynamic streaming algorithm that uses space and post-processing time to estimates the number of connected components of size at most within an additive error . The update time is .
By invoking Theorem 2 with parameter and , we get an estimator for the number of connected components of size smaller than within additive error at most . Since the number of components of size at least is at most , the estimator also approximates the total number of connected components within additive error at most . The space of the algorithm is , and we have the following result.
Theorem 3
Let be a constant. There exists a one-pass dynamic streaming algorithm that with constant success probability, estimates the number of connected components of a graph within an additive error in space and post-processing time.
Now we give the proof of Theorem 2. Recall that the vectors encode the information of the number of edges between C and .
Proof of Theorem 2
Let denote the number of connected components of size at most in G. Our algorithm for estimating is as follows. We first sample each vertex with probability . Let S be the set of sampled vertices. We then use the AGM sketch from Theorem 1 to maintain a spanning forest F of the subgraph induced by S. Then for each component C in F, we test whether C is actually a connected component in G by testing whether the vector is , which can be done by the AMS sketch. If , we set , otherwise set . Our estimator is then defined as , where C ranges over all components of F with size at most . See Algorithm 1 for the details.
Note that the algorithm samples at most vertices and we maintained an AGM sketch on G[S] and an AMS sketch for each sampled vertex, which imply that the space complexity of the algorithm is . By simple calculus, for any , it holds that , so the space is at most . The post-processing time is near linear in the space, and the update time is .
Now we prove the correctness of the above algorithm. First we note that the expected number of sampled vertices in Step (1) is np, and thus by Markov inequality, the probability that more than 16np vertices are sampled is at most . Also note that with probability at least , the AGM sketch returns a true spanning forest of G[S]. In addition, since the number of components in F is at most n, we will query the AMS sketch at most n times. Thus if we set the error probability of the AMS sketch to be , then with probability at least , all invocations of AMS sketches (with bits of space per sketch) for testing if will give the correct answer. Conditioned on this event, defined in Step (6) is exactly the number of connected components B of size in G such that all vertices in B are sampled out, which is true since for any component , if and only if C is a connected component in G.
Let be the connected components of size at most of G.
For any integer , let denote the set of connected components of size in G, that is, . Let . Note that . For any set B, let denote the indicator random variable that all the vertices in B have been sampled. Note that . Now by the above argument, , and . Furthermore, we have and thus .
Note that all ’s are mutually independent for all i, so it holds that
| 1 |
where we use the fact that , and . Then by Chebyshev’s inequality,
By the union bound, the algorithm will succeed with probability at least .
Approximating the Weight of Minimum Spanning Tree
We use the previous algorithm on estimating the number of connected components to approximate the weight of a minimum spanning tree of a weighted graph. Let be an integer, G be a connected graph with integer edge weights from , and be the weight of an MST of G. For any , let denote the subgraph of G consisting of all edges of weight at most . Let denote the number of connected components of . Chazelle et al. [8] give the following lemma relating the weight of MST to the number of connected components of .
Lemma 2
[8] It holds that .
For a connected graph with integer edge weights, the weight of any MST is at least , so it is sufficient to estimate within an additive error of for each . To do this, we can simply run parallel instances of Theorem 3, each of which sketches a subgraph . Then the space of the algorithm will be .
Theorem 4
Let be any constant. There exists a single-pass dynamic streaming algorithm that uses space and post-processing time to compute a -approximation of the weight of the MST.
We remark that Ahn et al. [2] have given a dynamic streaming algorithm for this problem for any graph with maximum edge weight upper bounded by , and their algorithm uses space . Our algorithm uses o(n) space for any connected graph with maximum edge weight bounded by (for constant ), which improves the algorithm of [2] in this setting. We also note that space is necessary for estimating the weight of MST for graphs with maximum edge weight at least for constant and some large universal constant c (see Theorem 10). Finally, we remark that the algorithm can also be extended to the setting where non-integral weights are allowed (see [8] for more details).
Dynamic Streaming Testers
In this section, we give our streaming testers for a number of graph properties, including k-edge connectivity, k-vertex connectivity, cycle-freeness, planar graph bipartiteness, and Eulerianity.
Testing k-Edge Connectivity
A graph is k-edge connected if the minimum cut of the graph has size at least k. We start from the simplest case, i.e., , which is equivalent to the problem of testing connectivity.
Connectivity
It is clear that if G is -far from being connected, one must add at least edges to make it connected, which implies that there are at least connected components in G [22, 36]. Therefore, we can distinguish a connected graph from any graph that is -far from being connected by estimating the number of connected components with an additive error . However, by a more careful analysis, we can reduce the space by a factor of .
Theorem 5
There exists a dynamic streaming tester for 1-edge connectivity that runs in post-processing time and space.
Proof
First observe that one can simply reject the input graph if , since in this case, the graph is disconnected. Thus, in the following we assume and our tester is described in Algorithm 2.
It is easy to see that Algorithm 2 only uses space, which is bounded by . The post-processing time is nearly linear in the size of S, since the AGM algorithm needs post-processing time, and we invoke at most |S| AMS queries, each of which takes time. The update time is .
For the correctness of the algorithm, we condition on the event that the number of sampled vertices is at most 16np, which occurs with probability at least , and on the event that the spanning forest F is constructed correctly, which occurs with probability 0.99. By setting the error probability of the AMS sketch to be (with an extra factor in space), with probability 0.99, all the answers from AMS sketches are all correct, and we also condition on this.
If G is connected, then it will always be accepted, since for each , , and conditioned on the correctness of the AMS sketch, will never be 0. On the other hand, if the graph is -far from being connected, the number of connected components in G, denoted as , is at least . Let denote all connected components in G. Let for . Using the inequality for all x, the probability that none of the components is entirely sampled out is . Then by the AM-GM inequality, this probability is at most
where we use the fact that and . So the probability that at least one of the components is sampled out is at least 15 / 16. Conditioned on this, for some component in G[S] and the algorithm will output Reject. By union bound, our algorithm will succeed with probability .
k-Edge Connectivity:
By using a slightly more involved argument and replacing AMS sketches with -sparse recovery sketches, we can generalize the above idea to testing k-edge connectivity for . We have the following theorem on testing k-edge connectivity.
Theorem 6
Let . There exists a single-pass dynamic streaming tester for k-edge connectivity with post-processing time and space .
In order to prove Theorem 6, we will use the following result by Orenstein and Ron [35], who have given, for any , a characterization of graphs that are -far from being k-edge connected (which simplifies the corresponding result in [22]). We define a subset C to be -extreme if and for any , .
Lemma 3
(Corollary 14 and Claim 16 in [35]) If G is -far from being k-edge connected, then there are at least disjoint subsets with an edge-cut smaller than k. For each such a subset C, it contains a minimal subset that is -extreme for some .
Now we present the proof of Theorem 6.
Proof of Theorem 6
It is clear that for any k-connected graph, and thus we can safely reject whenever . In the following, we will only consider the case that . Our tester is then described in Algorithm 3.
Note that the AGM sketch use space . In addition, each sampled vertex only needs to store a k-sparse recovery sketch, so the space complexity of the algorithm is . The post-processing time is near linear in the space, and the update time is .
For the correctness of the algorithm, we first note that if G is k-edge connected, then G will be accepted as long as there is no error happening when querying the k-sparse recovery sketches. This happens with probability by setting the error probability of the sketch to be , and we will condition on this event.
Now if G is -far from being k-edge connected, then from Lemma 3, it follows that there are at least disjoint -extreme subsets. Let be the set of these -extreme subsets where . Observe that for any -extreme subset B, the induced subgraph G[B] is connected. This is true since otherwise, there exists a subset satisfying , which implies that , contradicting to the assumption that B is -extreme.
Let be the event that is entirely sampled out, and be the event that none of the vertices in is sampled.
Note that our algorithm will reject if happens for some i, and thus our theorem will follow from the inequality that
| 2 |
Now we prove inequality (2). Note that the events are not necessarily independent across i since two different -extreme subsets may contain neighbors of each other or share neighbors. We have the following simple lemma to deal with this issue.
Lemma 4
There exists a set , with , such that:
for all and , and
.
Proof
We say and are neighbors, if . We iteratively construct the index set as follows. We start from the empty set and add one index at each step. Let denote the set that at the end of step t. In the -th step, we find the smallest set that is not a neighbor of for any and add the index , i.e., . Note that since each -extreme set has at most neighbors, we can always find such a set if . Let . Then Item 1 of the lemma follows by our construction. Since the set that we found in the t-th step may intersect with at most k sets, and is the smallest set that has no intersection with all sets found in the first steps, there must exist a partition of [s] into s / k sets , such that for any and , . Item 2 of the lemma then follows from our construction of the index subset , and the fact that .
Now we give a lower bound for . Let be the probability that all vertices in are sampled. Using the fact for all x and the AM-GM inequality, we have
Thus we have
since we set .
Now by the property of I as guaranteed in Lemma 4, it follows that and are independent for all . Hence, conditioned on the event , the probability of happening is
where in the penultimate inequality, we used the basic inequality that for ; the last inequality holds for or equivalent .
Finally, we have
We remark that the problem can still be solved in space for larger k by testing the neighborhood of all subsets of size smaller than in S, however the post-processing time will be . Also, is the most interesting case for us, since we are mostly interested in o(n) space algorithms.
k-Vertex Connectivity
A graph is k-vertex connected if the minimum vertex cut of the graph has size at least k, i.e. it remains connected whenever fewer than k vertices are removed. The following lemma on the structure of graphs that are -far from being k-vertex connected can be directly deduced from Corollary 19 in [35].
Lemma 5
If the graph is -far from k-vertex connected, then there exists at least subsets C of size at most such that G[C] is connected and .
Proof
(sketch) In Corollary 19 in [35], it is proven that for any directed graph G that is -from k-vertex connected, then there exists at least subsets C of size at most , and either or , where (resp., ) denotes the set of vertices in that are endpoints of incoming (resp., outgoing) edges incident to C.
On the other hand, in Sect. 5.3 in [35], it is proven that if an undirected graph G is -far from k-vertex connected, then the corresponding directed graph that is obtained by turning each undirected edge (u, v) into directed edges and is -far from being k-vertex connected. Therefore, there exists at least subsets C in of size at most , and either or . This directly implies that the corresponding set C in G satisfies that . Finally, if G[C] is not connected, then we can replace C by one maximal subset such that is connected. Note that . This completes the proof of the lemma.
Now we use the above lemma to show our k-vertex connectivity tester.
Theorem 7
Let . There exists a single-pass dynamic streaming tester for k-vertex connectivity with post-processing time and space complexity .
Proof
(sketch) We can also simply consider the case that , since otherwise the graph cannot be k-vertex connected and we can directly reject. Our approach for testing k-connectivity is similar to testing k-edge connectivity. The difference here is that now we cannot use the -sparse recovery sketch for the vector . Instead, for each vertex , we will maintain an exact -sparse recovery sketch of the vector (defined in Sect. 2.1), , for . Then for each detected connected component C of size smaller than in G[S] (by AGM sketch), recover from the sketch . If it succeeds, we get the set , and since we know C, we get . If , we reject. For any k-vertex connected graph, the tester will never reject if all the sparse recover sketches return correctly, which happens with high probability. On the other hand, if G is -far from k-vertex connected, by similar analysis as in k-edge connectivity together with Lemma 5, we know that with high probability, there is a subset such that G[C] is a connected component in G[S], and , and conditioned on this the algorithm will successfully recover , and reject with high probability. Here to make the analysis work, we have to set the sampling probability , so the space used is . Since the analysis is almost the same as k-edge connectivity, we omit the details here.
Testing Cycle-Freeness
Now we consider the problem of testing cycle-freeness, which is equivalent to testing if the graph is a forest. Let denote the number of connected components of the input graph G. Let be the connected components in G. Note that if G is cycle-free, then for each , , and thus the total number of edges in G is
that is, . If G is -far from being cycle-free, i.e., one has to delete more than edges to make it cycle-free, then . Therefore, to test cycle-freeness of a graph, it will be sufficient to approximate the number of connected components with additive error . One may try to directly invoke Algorithm 1 with parameter . However, m could be much smaller than n and we do not know m in advance. We overcome this obstacle by a case analysis.
Theorem 8
There exists a single-pass dynamic streaming algorithm that tests cycle-freeness of a graph with space and post-processing time .
Proof
Note that if , then the graph must contain at least one cycle, and thus we can safely reject the graph. In the following, we assume that . Note that if , then we can simply store whole graph and test if it is cycle-free, as the size of the graph is . In the following, we will assume that . Our algorithm for testing cycle-freeness depends on the construction of AGM sketch, in which each vertex u maintains a linear sketch of (denoted as ). Each such sketch has size and the property that (it consists of -samplers, see [2] for details). Our main idea is to maintain a sparse recovery sketch for the AGM sketch (i.e. a composition of sparse recovery sketch and AGM sketch). Now we describe our algorithm in Algorithm 4.
Note that the space used by the algorithm is as , and the post-processing time is near linear in space.
Now we prove the correctness of the algorithm. We define to be a subgraph which consists of all the vertices of positive degree. Let . Note that .
If , then the vector is -sparse, since for all isolated vertices u, we have , and thus we can recover the entire exactly. Then by Step 2-(c) and Theorem 1, we can get the exact number of components of . Since the number of vertices of is |Y|, and is the total number of edges, then the graph is cycle-free if and only if .
If , then conditioned on the event that all for are correct (which occurs with high probability), our estimator approximates the number of isolated vertices in G, denoted by , with an additive error with probability at least (by our choice that and similar analysis for the proof of Theorem 2). We will condition on this event. Since and , we have that .
Now note that by Theorem 2, is an estimator for the number, denoted by , of components in of size smaller than with additive error . This follows by the upper bound of the variance of the estimator (which can be shown similarly to inequality (1) in Sect. 3) and the Chebyshev’s inequality. Now note that the additive error is at most for some constant t since and . That is, with high probability, . In the following, we condition on this event.
Let L be the number of components in of size larger than . Note that each such component has at least edges. Thus, , which gives that by our choice of .
If the original graph G is cycle-free, then the number of connected components of G equals , i.e., . Thus, we have that . The algorithm will output Accept.
If G is -far from being cycle-free, then . Thus, . The algorithm will output Reject.
Thus, our algorithm can distinguish cycle-free graphs from those graphs that are -far from being cycle-free with probability at least 2 / 3. This completes the proof of the theorem.
Testing Bipartiteness of the Planar Graphs
Now we consider the problem of testing if a planar graph is bipartite or -far from bipartite. Here a planar graph is -far from bipartite if one has to delete at least edges to get a bipartite graph. Czumaj et al. [12] showed the following result1.
Lemma 6
[12] For any (simple) planar graph G that is -far from bipartite, then G has at least edge-disjoint odd-length cycles of length at most each, where .
By the above lemma, we only need to sample each edge independently with some probability (rather than vertices as we did before) of the graph so that with high probability the resulting sampled graph contains at least one short odd-length cycle. The edge-sampling process can be done by using hash functions (see e.g. [3]). Similar to our previous analysis, it will be sufficient to set the sample probability to , which implies that the space used is . We omit the details here.
Testing Eulerianity
Note that the algorithm for connectivity testing can be directly used to testing Eulerianity. A graph G is Eulerian if there is a path in the graph that traverses each edge exactly once, or equivalently, if G is connected and the degrees of all vertices are even or exactly two vertices have odd degrees. Note that if graph G is -far from being Eulerian then either G has connected components (i.e. far from being connected) or has vertices of odd degree (cf., [22, 36]). Then one can test Eulerianity by first invoking the previous algorithm on testing connectivity, and then sample vertices and check if some sampled vertex has odd degree. The post-processing time and space complexity of the final algorithm are for some universal constant c.
Lower Bounds
In this section we present lower bounds, which hold in the insertion-only model. Our proofs are based on the reductions to the Boolean Hidden Hypermatching (BHH) problem (See [42]), which are in the same spirit as the lower bound proof for the Cycle Counting problem in [42]. We first give the definition of the boolean hidden hypermatching problem.
Definition 1
() In the this problem, Alice gets a boolean vector , where for some integer k. Bob gets a partition (or hypermatching) of the set [n], , where the size of each is t, and a vector . For convenience, we will also use the corresponding n-dimensional boolean indicator vector to represent , and let M be a matrix, the i row of which is . The promise of the input is either or , where all the operations are modulo 2. The goal of the problem is to output 1 when , and output 0 otherwise.
We have the following lower bound from [42].
Theorem 9
[42] The randomized one-way communication complexity of when for some integer is .
Our lower bounds will be built upon the following basic construction.
Construction ofG(x, M). Given vector x and matrix M respectively, Alice and Bob construct a bipartite graph , where and , as follows. Given , Alice adds a perfect matching between U and V. For each , if , she adds two parallel edges and ; otherwise if , she adds two crossing edges and (see Fig. 1).
Fig. 1.

Parallel (left) and crossing (right) matching according to the value of
Given M, Bob will do the following. For each and the hyperedge (that corresponds to the ith row ), we use to denote the jth element in and we let or or . For each and , Bob adds two edges and (see Fig. 2).
Fig. 2.

Bob connects and for each
Observe that the edges added by Alice and Bob form two paths over vertex set , where starts from and starts from for each i. The entire graph G(x, M) consists of 2n / t disjoint paths . It also has the following property.
Fact 1
Based on the value of , we have: 1) if , then is a path from to and is a path from to ; 2) if , then is a path from to and is a path from to .
Minimum Spanning Tree
Theorem 10
In the insertion-only model, if all edges of the graph have weights in [W], any algorithm that -approximates the weight of the MST must use bits of space.
Proof
Given x and M, Alice and Bob first construct the graph G(x, M) as described above. Next Bob adds and if ; adds and if . The weight of all the edges added so far is 1. Next, regardless of the value of , Bob places edges with weight 1 for and edges with weight W for each , so that the graph become connected. By similar argument as above, if , all the edges must be picked in any minimum spanning tree, since each of these edges forms a cut, and thus the weight of any MST is , where we set . On the other hand, when , the weight of the MST is , since in this case, the graph is already connected without those edges with weight W. So if the algorithm can compute an -approximation of the weight of the minimum spanning tree, it solves the problem. This completes the proof.
Testing Connectivity
Theorem 11
In the insertion-only model, to distinguish whether a graph of 4n vertices is connected or -far from being connected, any algorithm must use bits of space.
Proof
Given x and M, Alice and Bob first construct the graph G(x, M). Next Bob adds another set of edges based on vector w. If , he adds and ; if , he adds and . So when , and become 2 disjoint cycles. On the other hand, when , and together form a larger cycle. Now Bob places in E for which connect with for all , i.e. all the paths in G(x, M) with even indices become a connected component. The total number of edges is . When , the graph has components which is -far from connected; when the graph is connected. So if a streaming algorithm can distinguish whether a graph of size 4n is connected or 1 / 8t-far from being connected, it solves , since Alice can first run the algorithm on her part of the graph and send the memory to Bob, and then Bob continues to run the algorithm on his part and output the answer. Therefore, the communication lower bound of implies a space lower bound of testing connectivity.
Testing Cycle-Freeness
As in the proof of Theorem 11, given x and M, Alice and Bob first construct G(x, M). Then, for , Bob adds if ; adds if . The total number of edges is less than 8n. Through similar arguments, it is easy to verify that if if , the graph has exactly n / t cycles and n / t paths, which is 1 / 8t-far from cycle-free. On the contrary, if , the graph has n / t paths and no cycle. So if an algorithm can distinguish whether a graph of size 4n is cycle-free or 1 / 8t-far from cycle-free, it solves .
Theorem 12
In the insertion-only model, any algorithm that can distinguish whether a graph of 4n vertices is cycle-free or 1 / 8t-far from being cycle-free, must use bits of space.
Testing Bipartiteness of Planar Graphs
Alice and Bob first construct the graph G(x, M). Next, for each , Bob adds edges and , where are new vertices. For , Bob also adds and if ; adds and if . For this problem we assume t is odd. So by similar arguments, we can easily verify that, if , the graph contains 2n / t edge-disjoint cycles of length , and if , the graph has no odd cycle, and thus bipartite. The graph constructed is planar and has vertices and edges, so we have the following lower bound for testing bipartiteness.
Theorem 13
In the insertion-only model, any algorithm that can distinguish whether a planar graph of vertices is bipartite or -far from being bipartite, must use bits space.
Footnotes
In [12], -far is expressed as edges, rather than edges as in our definition, that has to be deleted to obtain a bipartite graph. However, Lemma 6 directly follows from their proof.
A preliminary version of this paper appeared in the Proceedings of the 43rd International Colloquium on Automata, Languages and Programming (ICALP), Rome, Italy, July 2016.
Zengfeng Huang: Supported by Shanghai Science and Technology Commission (Grant No. 17JC1420200) and Australian Research Council Discovery Grant (DP150102728).
Pan Peng: Work done while the author was at TU Dortmund, Germany and supported by ERC grant No. 307696.
Publisher's Note
Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Contributor Information
Zengfeng Huang, Email: huangzf@fudan.edu.cn.
Pan Peng, Email: p.peng@sheffield.ac.uk.
References
- 1.Ahn, K.J., Cormode, G., Guha, S., McGregor, A., Wirth, A.: Correlation clustering in data streams. In: Proceedings of the 32nd International Conference on Machine Learning, ICML, pp. 6–11 (2015)
- 2.Ahn, K.J., Guha, S., McGregor, A.: Analyzing graph structure via linear measurements. In: Proceedings of the Twenty-third Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 459–467. SIAM, Philadelphia (2012)
- 3.Ahn, K.J., Guha, S., McGregor, A.: Graph sketches: sparsification, spanners, and subgraphs. In: Proceedings of the 31st Symposium on Principles of Database Systems, pp. 5–14. ACM, New York (2012)
- 4.Alon, N., Matias, Y., Szegedy, M.: The space complexity of approximating the frequency moments. In: Proceedings of the Twenty-Eighth Annual ACM Symposium on Theory of Computing, pp. 20–29. ACM, New York (1996)
- 5.Assadi, S., Khanna, S., Li, Y., Yaroslavtsev, G.: Maximum matchings in dynamic graph streams and the simultaneous communication model. In: Proceedings of the Twenty-Seventh Annual ACM-SIAM Symposium on Discrete Algorithms, SODA ’16, pp. 1345–1364. SIAM, Philadelphia (2016)
- 6.Bhattacharya, S., Henzinger, M., Nanongkai, D., Tsourakakis, C.E.: Space-and time-efficient algorithm for maintaining dense subgraphs on one-pass dynamic streams. In: ACM Symposium on Theory of Computing (2015)
- 7.Bury, M., Schwiegelshohn, C.: Sublinear estimation of weighted matchings in dynamic data streams. ESA (2015)
- 8.Chazelle B, Rubinfeld R, Trevisan L. Approximating the minimum spanning tree weight in sublinear time. SIAM J. Comput. 2005;34(6):1370–1379. doi: 10.1137/S0097539702403244. [DOI] [Google Scholar]
- 9.Chitnis, R., Cormode, G., Esfandiari, H., Hajiaghayi, M., McGregor, A., Monemizadeh, M., Vorotnikova, S.: Kernelization via sampling with applications to dynamic graph streams. SODA (2016)
- 10.Chitnis, R., Cormode, G., Hajiaghayi, M., Monemizadeh, M.: Parameterized streaming: maximal matching and vertex cover. In: Proceedings of the Twenty-Sixth Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 1234–1251. SIAM, Philadelphia (2015)
- 11.Czumaj A, Ergün F, Fortnow L, Magen A, Newman I, Rubinfeld R, Sohler C. Approximating the weight of the euclidean minimum spanning tree in sublinear time. SIAM J. Comput. 2005;35(1):91–109. doi: 10.1137/S0097539703435297. [DOI] [Google Scholar]
- 12.Czumaj, A., Monemizadeh, M., Onak, K., Sohler, C.: Planar graphs: random walks and bipartiteness testing. In: Foundations of Computer Science (FOCS), 2011 IEEE 52nd Annual Symposium on, pp. 423–432. IEEE (2011)
- 13.Czumaj A, Sohler C. Estimating the weight of metric minimum spanning trees in sublinear time. SIAM J. Comput. 2009;39(3):904–922. doi: 10.1137/060672121. [DOI] [Google Scholar]
- 14.Esfandiari, H., Hajiaghayi, M., Woodruff, D.P.: Brief announcement: applications of uniform sampling: densest subgraph and beyond. In: Proceedings of the 28th ACM Symposium on Parallelism in Algorithms and Architectures, SPAA 2016, pp. 397–399 (2016)
- 15.Esfandiari, H., Hajiaghayi, M.T., Liaghat, V., Monemizadeh, M., Onak, K.: Streaming algorithms for estimating the matching size in planar graphs and beyond. In: Proceedings of the Twenty-Sixth Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 1217–1233. SIAM, Philadelphia (2015)
- 16.Fafianie, S., Kratsch, S.: Streaming kernelization. In: Mathematical Foundations of Computer Science 2014, pp. 275–286. Springer, Berlin (2014)
- 17.Feigenbaum J, Kannan S, McGregor A, Suri S, Zhang J. On graph problems in a semi-streaming model. Theor. Comput. Sci. 2005;348(2):207–216. doi: 10.1016/j.tcs.2005.09.013. [DOI] [Google Scholar]
- 18.Feigenbaum J, Kannan S, McGregor A, Suri S, Zhang J. Graph distances in the data-stream model. SIAM J. Comput. 2008;38(5):1709–1727. doi: 10.1137/070683155. [DOI] [Google Scholar]
- 19.Frahling, G., Indyk, P., Sohler, C.: Sampling in dynamic data streams and applications. In: Proceedings of the Twenty-First Annual Symposium on Computational Geometry, pp. 142–149. ACM, New York (2005)
- 20.Goldreich, O.: Introduction to testing graph properties. In: Property Testing, pp. 105–141. Springer, Berlin (2011)
- 21.Goldreich O, Goldwasser S, Ron D. Property testing and its connection to learning and approximation. J. ACM. 1998;45(4):653–750. doi: 10.1145/285055.285060. [DOI] [Google Scholar]
- 22.Goldreich O, Ron D. Property testing in bounded degree graphs. Algorithmica. 2002;32:302–343. doi: 10.1007/s00453-001-0078-7. [DOI] [Google Scholar]
- 23.Guha, S., McGregor, A., Tench, D.: Vertex and hyperedge connectivity in dynamic graph streams. In: Proceedings of the 34th ACM Symposium on Principles of Database Systems, pp. 241–247. ACM, New York (2015)
- 24.Henzinger, M.R., Raghavan, P., Rajagopalan, S.: Computing on data streams. In: External Memory Algorithms, Proceedings of a DIMACS Workshop, New Brunswick, New Jersey, USA, May 20–22, pp. 107–118 (1998)
- 25.Jowhari, H.: Estimating the number of connected components in graph streams. Personal Communication
- 26.Kapralov, M., Khanna, S., Sudan, M.: Approximating matching size from random streams. In: Proceedings of the Twenty-Fifth Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 734–751. SIAM, Philadelphia (2014)
- 27.Kapralov, M., Khanna, S., Sudan, M.: Streaming lower bounds for approximating max-cut. In: Proceedings of the Twenty-Sixth Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 1263–1282. SIAM, Philadelphia (2015)
- 28.Kapralov, M., Lee, Y.T., Musco, C., Sidford, A.: Single pass spectral sparsification in dynamic streams. In: Foundations of Computer Science (FOCS), 2014 IEEE 55th Annual Symposium on, pp. 561–570. IEEE (2014)
- 29.Kapralov, M., Woodruff, D.: Spanners and sparsifiers in dynamic streams. In: Proceedings of the 2014 ACM symposium on Principles of distributed computing, pp. 272–281. ACM, New York (2014)
- 30.Kogan, D., Krauthgamer, R.: Sketching cuts in graphs and hypergraphs. In: Proceedings of the 2015 Conference on Innovations in Theoretical Computer Science, pp. 367–376. ACM, New York (2015)
- 31.Konrad, C.: Maximum matching in turnstile streams. ESA (2015)
- 32.McGregor A. Graph stream algorithms: a survey. ACM SIGMOD Rec. 2014;43(1):9–20. doi: 10.1145/2627692.2627694. [DOI] [Google Scholar]
- 33.McGregor, A., Tench, D., Vorotnikova, S., Vu, H.T.: Densest subgraph in dynamic graph streams. MFCS (2015)
- 34.Muthukrishnan S. Data streams: algorithms and applications. Theor. Comput. Sci. 2005;1(2):117–236. [Google Scholar]
- 35.Orenstein Y, Ron D. Testing eulerianity and connectivity in directed sparse graphs. Theor. Comput. Sci. 2011;412(45):6390–6408. doi: 10.1016/j.tcs.2011.06.038. [DOI] [Google Scholar]
- 36.Parnas M, Ron D. Testing the diameter of graphs. Random Struct. Algorithms. 2002;20(2):165–183. doi: 10.1002/rsa.10013. [DOI] [Google Scholar]
- 37.Peng, P., Sohler, C.: Estimating graph parameters from random order streams. In: Proceedings of the Twenty-Ninth Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 2449–2466. SIAM, Philadelphia (2018)
- 38.Price, E.: Efficient sketches for the set query problem. In: Proceedings of the twenty-second annual ACM-SIAM symposium on Discrete Algorithms, pp. 41–56. SIAM, Philadelphia (2011)
- 39.Ron D. Algorithmic and analysis techniques in property testing: foundations and trends . Theor. Comput. Sci. 2010;5(2):73–205. [Google Scholar]
- 40.Rubinfeld R, Shapira A. Sublinear time algorithms. SIAM J. Discrete Math. 2011;25(4):1562–1588. doi: 10.1137/100791075. [DOI] [Google Scholar]
- 41.Sun, X., Woodruff, D.P.: Tight bounds for graph problems in insertion streams. In: The 18th International Workshop on Approximation Algorithms for Combinatorial Optimization Problems (APPROX’2015) (2015)
- 42.Verbin, E., Yu, W.: The streaming complexity of cycle counting, sorting by reversals, and other problems. In: Proceedings of the twenty-second annual ACM-SIAM symposium on Discrete Algorithms, pp. 11–25. SIAM, Philadelphia (2011)
- 43.Yoshida, Y., Ito, H.: Property testing on k-vertex-connectivity of graphs. In: Automata, Languages and Programming, pp. 539–550. Springer, Berlin (2008)



