Abstract
Recent work by Elmasry et al. (STACS 2015) and Asano et al. (ISAAC 2014), reconsidered classical fundamental graph algorithms focusing on improving the space complexity. Elmasry et al. gave, among others, implementations of breadth first search (BFS) and depth first search (DFS) in a graph on n vertices and m edges, taking \(O(m+n)\) time using O(n) and \(O(n \lg \lg n)\) bits of space respectively improving the naive \(O(n \lg n)\)(We use \(\lg \) to denote logarithm to the base 2.) bits implementation. We continue this line of work focusing on space.
Our first result is a simple data structure that can maintain any subset S of a universe of n elements using \(n+o(n)\) bits and support in constant time, apart from the standard insert, delete and membership queries, the operation findany that finds and returns any element of the set (or outputs that the set is empty). Using this we give a BFS implementation that takes \(O(m+n)\) time using at most \(2n+o(n)\) bits. Later, we further improve the space requirement of BFS to at most \(1.585n + o(n)\) bits albeit with a slight increase in running time to \(O(m \lg n f(n))\) time where f(n) is any extremely slow growing function of n. These improve the space by a constant factor from earlier representations.
We demonstrate the use of our data structure by developing another data structure using it that can represent a sequence of n non-negative integers \(x_1, x_2, \ldots x_n\) using at most \(\sum _{i=1}^n x_i + 2n + o(\sum _{i=1}^n x_i+n)\) bits and, in constant time, determine whether the i-th element is 0 or decrement it otherwise. We use this data structure to output the vertices of a
-
directed acyclic graph in topological sorted order in \(O(m+n)\) time and \(O(m+n)\) bits, and
-
graph with degeneracy d in degeneracy order in O(nd) time using O(nd) bits.
We also discuss an algorithm for finding a minimum weight spanning tree of a weighted undirected graph using at most \(n+o(n)\) bits.
For DFS we give an \(O(m+n)\) bits implementation for finding a chain decomposition of a connected undirected graph, and to find cut vertices, bridges and maximal two connected subgraphs of a connected graph. We also provide a O(n) bits implementations for finding strongly connected components of a directed graph, to output the vertices of a directed acyclic graph in a topologically sorted manner, and to find a sparse biconnected subgraph of a biconnected graph. These improve the space required for earlier implementations from \(\varOmega (n \lg n)\) bits.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
Since our initial submission to COCOON, Hagerup and Kammer [19] have reported a structure with \(n+o(n)\) bits for the data structure and hence obtaining a similar bound as ours for BFS.
- 2.
Hagerup and Kammer [19] have recently reported a structure with \(n+o(n)\) bits for the data structure supporting the same set of operations.
- 3.
Proofs of results marked with \((\spadesuit )\) will appear in full version.
- 4.
Hagerup and Kammer [19] in their recent paper obtain a better time bound using the same space.
References
Arora, S., Barak, B.: Computational Complexity - A Modern Approach. Cambridge University Press, Cambridge (2009)
Asano, T., et al.: Depth-first search using O(n) bits. In: Ahn, H.-K., Shin, C.-S. (eds.) ISAAC 2014. LNCS, vol. 8889, pp. 553–564. Springer, Heidelberg (2014)
Asano, T., Kirkpatrick, D., Nakagawa, K., Watanabe, O.: \(\widetilde{O}(\sqrt{n})\)-space and polynomial-time algorithm for planar directed graph reachability. In: Ésik, Z., Csuhaj-VarjĂº, E., Dietzfelbinger, M. (eds.) MFCS 2014, Part II. LNCS, vol. 8635, pp. 45–56. Springer, Heidelberg (2014)
Asano, T., Mulzer, W., Rote, G., Wang, Y.: Constant-work-space algorithms for geometric problems. JoCG 2(1), 46–68 (2011)
Banerjee, N., Chakraborty, S., Raman, V., Roy, S., Saurabh, S.: Time-space tradeoffs for dynamic programming algorithms in trees and bounded treewidth graphs. In: Xu, D., Du, D., Du, D. (eds.) COCOON 2015. LNCS, vol. 9198, pp. 349–360. Springer, Heidelberg (2015)
Barba, L., Korman, M., Langerman, S., Sadakane, K., Silveira, R.I.: Space-time trade-offs for stack-based algorithms. Algorithmica 72(4), 1097–1129 (2015)
Barnes, G., Buss, J., Ruzzo, W., Schieber, B.: A sublinear space, polynomial time algorithm for directed s-t connectivity. SICOMP 27(5), 1273–1282 (1998)
Batagelj, V., Zaversnik, M.: An \({\rm O}(m)\) algorithm for cores decomposition of networks. CoRR cs.DS/0310049 (2003)
Brandes, U.: Eager \(st\)-ordering. In: Möhring, R.H., Raman, R. (eds.) ESA 2002. LNCS, vol. 2461, pp. 247–256. Springer, Heidelberg (2002)
Brodnik, A., Carlsson, S., Demaine, E.D., Munro, J.I., Sedgewick, R.D.: Resizable arrays in optimal time and space. In: Dehne, F., Gupta, A., Sack, J.-R., Tamassia, R. (eds.) WADS 1999. LNCS, vol. 1663, pp. 37–48. Springer, Heidelberg (1999)
Chakraborty, D., Pavan, A., Tewari, R., Vinodchandran, N.V., Yang, L.: New time-space upperbounds for directed reachability in high-genus and H-minor-free graphs. In: FSTTCS, pp. 585–595 (2014)
Clark, D.: Compact pat trees. Ph.D. thesis, University of Waterloo, Canada (1996)
Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C.: Introduction to Algorithms, 3rd edn. MIT Press, Cambridge (2009)
Darwish, O., Elmasry, A.: Optimal time-space tradeoff for the 2D convex-hull problem. In: Schulz, A.S., Wagner, D. (eds.) ESA 2014. LNCS, vol. 8737, pp. 284–295. Springer, Heidelberg (2014)
Elmasry, A., Hagerup, T., Kammer, F.: Space-efficient basic graph algorithms. In: 32nd STACS, pp. 288–301 (2015)
Eppstein, D., Loffler, M., Strash, D.: Listing all maximal cliques in large sparse real-world graphs. ACM J. Exp. Algorithmics 18, 1–3 (2013)
Frederickson, G.N.: Upper bounds for time-space trade-offs in sorting and selection. J. Comput. Syst. Sci. 34(1), 19–26 (1987)
Gupta, A., Hon, W.-K., Shah, R., Vitter, J.S.: A framework for dynamizing succinct data structures. In: Arge, L., Cachin, C., Jurdziński, T., Tarlecki, A. (eds.) ICALP 2007. LNCS, vol. 4596, pp. 521–532. Springer, Heidelberg (2007)
Hagerup, T., Kammer, F.: Succinct choice dictionaries. CoRR abs/1604.06058 (2016)
Hon, W.K., Sadakane, K., Sung, W.K.: Succinct data structures for searchable partial sums with optimal worst-case performance. Theor. Comput. Sci. 412(39), 5176–5186 (2011)
Munro, J.I.: Tables. In: Chandru, V., Vinay, V. (eds.) FSTTCS 1996. LNCS, vol. 1180, pp. 37–42. Springer, Heidelberg (1996)
Munro, J.I., Paterson, M.: Selection and sorting with limited storage. Theor. Comput. Sci. 12, 315–323 (1980)
Munro, J.I., Raman, V.: Selection from read-only memory and sorting with minimum data movement. Theor. Comput. Sci. 165(2), 311–323 (1996)
Reingold, O.: Undirected connectivity in log-space. J. ACM 55(4), 1–17 (2008)
Schmidt, J.M.: A simple test on 2-vertex- and 2-edge-connectivity. Inf. Process. Lett. 113(7), 241–244 (2013)
Acknowledgement
The authors thank Saket Saurabh for suggesting the exploration of algorithms using \(O(m+n)\) bits for DFS and Anish Mukherjee for helpful discussions.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2016 Springer International Publishing Switzerland
About this paper
Cite this paper
Banerjee, N., Chakraborty, S., Raman, V. (2016). Improved Space Efficient Algorithms for BFS, DFS and Applications. In: Dinh, T., Thai, M. (eds) Computing and Combinatorics . COCOON 2016. Lecture Notes in Computer Science(), vol 9797. Springer, Cham. https://doi.org/10.1007/978-3-319-42634-1_10
Download citation
DOI: https://doi.org/10.1007/978-3-319-42634-1_10
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-42633-4
Online ISBN: 978-3-319-42634-1
eBook Packages: Computer ScienceComputer Science (R0)