, Volume 72, Issue 4, pp 1097–1129 | Cite as

Space–Time Trade-offs for Stack-Based Algorithms

  • Luis Barba
  • Matias Korman
  • Stefan Langerman
  • Kunihiko Sadakane
  • Rodrigo I. Silveira


In memory-constrained algorithms, access to the input is restricted to be read-only, and the number of extra variables that the algorithm can use is bounded. In this paper we introduce the compressed stack technique, a method that allows to transform algorithms whose main memory consumption takes the form of a stack into memory-constrained algorithms. Given an algorithm \(\mathcal {A}\) that runs in \(O(n)\) time using a stack of length \(\Theta (n)\), we can modify it so that it runs in \(O(n^2\log n/2^s)\) time using a workspace of \(O(s)\) variables (for any \(s\in o(\log n)\)) or \(O(n^{1+1/\log p})\) time using \(O(p\log _p n)\) variables (for any \(2\le p\le n\)). We also show how the technique can be applied to solve various geometric problems, namely computing the convex hull of a simple polygon, a triangulation of a monotone polygon, the shortest path between two points inside a monotone polygon, a 1-dimensional pyramid approximation of a 1-dimensional vector, and the visibility profile of a point inside a simple polygon. Our approach improves or matches up to a \(O(\log n)\) factor the running time of the best-known results for these problems in constant-workspace models (when they exist), and gives a trade-off between the size of the workspace and running time. To the best of our knowledge, this is the first general framework for obtaining memory-constrained algorithms.


Memory constrained algorithms Space–time trade-off Stack algorithms Constant workspace 



We thank the anonymous referee for their thorough proofread as well as for pointing us to [14]. We also thank Mikkel Abrahamsen for useful discussions and comments. M.K was partially supported by the Secretary for Universities and Research of the Ministry of Economy and Knowledge of the Government of Catalonia, the European Union, and the JST, ERATO, Kawarabayashi Large Graph Project. R.S. was partially supported by FP7 Marie Curie Actions Individual Fellowship PIEF-GA-2009-251235 and by FCT through grant SFRH/BPD/88455/2012. M.K and R.S. were also supported by projects MINECO MTM2012-30951 and Gen. Cat. DGR2009SGR1040 and by ESF EUROCORES program EuroGIGA-ComPoSe IP04-MICINN project EUI-EURC-2011 4306. R. Silveira was also affiliated with Universitat Politècnica de Catalunya (UPC), Barcelona, Spain. S. Langerman is Directeur de Recherches du F.R.S.-FNRS.


  1. 1.
    Abrahamsen, M.: Constant-workspace algorithms for visibility problems in the plane. Master’s thesis, University of Copenhagen (2013)
  2. 2.
    Abrahamsen, M.: An optimal algorithm computing edge-to-edge visibility in a simple polygon. In: CCCG, pp. 157–162 (2013)Google Scholar
  3. 3.
    Akra, M., Bazzi, L.: On the solution of linear recurrence equations. Comput. Optim. Appl. 10(2), 195–210 (1998)MATHMathSciNetCrossRefGoogle Scholar
  4. 4.
    Aloupis, G.: A history of linear-time convex hull algorithms for simple polygons.
  5. 5.
    Arora, S., Barak, B.: Computational Complexity: A Modern Approach. Cambridge University Press, Cambridge (2009)CrossRefGoogle Scholar
  6. 6.
    Asano, T., Buchin, K., Buchin, M., Korman, M., Mulzer, W., Rote, G., Schulz, A.: Memory-constrained algorithms for simple polygons. Comput. Geom. 46(8), 959–969 (2013)Google Scholar
  7. 7.
    Asano, T., Mulzer, W., Rote, G., Wang, Y.: Constant-work-space algorithms for geometric problems. J. Comput. Geom. 2(1), 46–68 (2011)MathSciNetGoogle Scholar
  8. 8.
    Asano, T., Mulzer, W., Wang, Y.: Constant-work-space algorithms for shortest paths in trees and simple polygons. J. Graph Algorithms Appl. 15(5), 569–586 (2011)MATHMathSciNetCrossRefGoogle Scholar
  9. 9.
    Barba, L., Korman, M., Langerman, S., Sadakane, K., Silveira, R.: Space–time trade-offs for stack-based algorithms. In STACS, pp. 281–292 (2013)Google Scholar
  10. 10.
    Barba, L., Korman, M., Langerman, S., Silveira, R. I.: Computing the visibility polygon using few variables. Comput. Geom. Theory Appl. 47(9), 918–926 (2014)Google Scholar
  11. 11.
    Bloch, I.: Unifying quantitative, semi-quantitative and qualitative spatial relation knowledge representations using mathematical morphology. In TFCV, pp. 153–164 (2003)Google Scholar
  12. 12.
    Brönnimann, H., Chan, T.M.: Space-efficient algorithms for computing the convex hull of a simple polygonal line in linear time. Comput. Geom. Theory Appl. 34(2), 75–82 (2006)Google Scholar
  13. 13.
    Chan, T.M.: Comparison-based time-space lower bounds for selection. ACM Trans Algorithms, 6:26:1–26:16 (2010)Google Scholar
  14. 14.
    Chan, T.M., Chen, E.Y.: Multi-pass geometric algorithms. Discret. Comput. Geom. 37(1), 79–102 (2007)MATHMathSciNetCrossRefGoogle Scholar
  15. 15.
    Chazelle, B.: Triangulating a simple polygon in linear time. Discret. Comput. Geom. 6, 485–524 (1991)MATHMathSciNetCrossRefGoogle Scholar
  16. 16.
    Chun, J., Sadakane, K., Tokuyama, T.: Linear time algorithm for approximating a curve by a single-peaked curve. Algorithmica 44(2), 103–115 (2006)MATHMathSciNetCrossRefGoogle Scholar
  17. 17.
    Cook, S.A.: Deterministic CFL’s are accepted simultaneously in polynomial time and log squared space. In STOCS, pp. 338–345 (1979)Google Scholar
  18. 18.
    De, M., Maheshwari, A., Nandy, S.C.: Space-efficient algorithms for visibility problems in simple polygon. CoRR, abs/1204.2634 (2012)Google Scholar
  19. 19.
    De, M., Nandy, S.C., Roy, S.: Convex hull and linear programming in read-only setup with limited work-space. CoRR, abs/1212.5353 (2012)Google Scholar
  20. 20.
    Dymond, P.W., Ruzzo, W.L.: Parallel RAMs with owned global memory and deterministic context-free language recognition. J. ACM 47(1), 16–45 (2000)MATHMathSciNetCrossRefGoogle Scholar
  21. 21.
    Frederickson, G.N.: Upper bounds for time-space trade-offs in sorting and selection. J. Comput. Syst. Sci. 34(1), 19–26 (1987)MATHMathSciNetCrossRefGoogle Scholar
  22. 22.
    Fukuda, T., Morimoto, Y., Morishita, S., Tokuyama, T.: Data mining with optimized two-dimensional association rules. ACM Trans. Database Syst. 26(2), 179–213 (2001)MATHCrossRefGoogle Scholar
  23. 23.
    Garey, M.R., Johnson, D.S., Preparata, F.P., Tarjan, R.E.: Triangulating a simple polygon. Inf. Process. Lett. 7(4), 175–179 (1978)MATHMathSciNetCrossRefGoogle Scholar
  24. 24.
    Ghosh, S.: Visibility Algorithms in the Plane. Cambridge University Press, Cambridge (2007)MATHCrossRefGoogle Scholar
  25. 25.
    Greenwald, M., Khanna, S.: Space-efficient online computation of quantile summaries. In SIGMOD, pp. 58–66 (2001)Google Scholar
  26. 26.
    Guibas, L.J., Hershberger, J.: Optimal shortest path queries in a simple polygon. J. Comput. Syst. Sci. 39(2), 126–152 (1989)MATHMathSciNetCrossRefGoogle Scholar
  27. 27.
    Jacobson, G.: Succinct Static Data Structures. PhD thesis, Carnegie-Mellon, Jan. 1989. Tech Rep CMU-CS-89-112Google Scholar
  28. 28.
    Jarvis, R.: On the identification of the convex hull of a finite set of points in the plane. Inf. Process. Lett. 2(1), 18–21 (1973)MATHMathSciNetCrossRefGoogle Scholar
  29. 29.
    Joe, B., Simpson, R.B.: Corrections to Lee’s visibility polygon algorithm. BIT Numer. Math. 27, 458–473 (1987)MATHCrossRefGoogle Scholar
  30. 30.
    Lee, D.T.: On finding the convex hull of a simple polygon. Int. J. Parallel Program. 12(2), 87–98 (1983)MATHGoogle Scholar
  31. 31.
    Mitchell, J.S.B.: Shortest paths and networks. In: Goodman, J.E., O’Rourke, J. (eds.) Handbook of Discrete and Computational Geometry, pp. 607–642. CRC Press LLC, Boca Raton (2004)Google Scholar
  32. 32.
    Morimoto, Y., Fukuda, T., Morishita, S., Tokuyama, T.: Implementation and evaluation of decision trees with range and region splitting. Constraints 2, 401–427 (1997)MATHMathSciNetCrossRefGoogle Scholar
  33. 33.
    Munro, J.I., Paterson, M.: Selection and sorting with limited storage. Theor. Comput. Sci. 12, 315–323 (1980)MATHMathSciNetCrossRefGoogle Scholar
  34. 34.
    Munro, J.I., Raman, V.: Selection from read-only memory and sorting with minimum data movement. Theor. Comput. Sci. 165, 311–323 (1996)MATHMathSciNetCrossRefGoogle Scholar
  35. 35.
    O’Rourke, J.: Computational Geometry in C. Cambridge University Press, Cambridge (1994)MATHGoogle Scholar
  36. 36.
    O’Rourke, J.: Visibility. Handbook of Discrete and Computational Geometry, vol. 28, 2nd edn, pp. 643–664. CRC Press Inc., Boca Raton (2004)Google Scholar
  37. 37.
    Pilz, A.: Personal communication (2013)Google Scholar
  38. 38.
    Raman, V., Ramnath, S.: Improved upper bounds for time-space tradeoffs for selection with limited storage. In SWAT, pp. 131–142 (1998)Google Scholar
  39. 39.
    von Braunmühl, B., Cook, S.A., Mehlhorn, K., Verbeek, R.: The recognition of deterministic CFL’s in small time and space. Inf. Control 56(1/2), 34–51 (1983)MATHCrossRefGoogle Scholar

Copyright information

© Springer Science+Business Media New York 2014

Authors and Affiliations

  • Luis Barba
    • 1
  • Matias Korman
    • 2
  • Stefan Langerman
    • 3
  • Kunihiko Sadakane
    • 4
  • Rodrigo I. Silveira
    • 5
  1. 1.School of Computer Science, Carleton UniversityOttawaCanada
  2. 2.National Institute of InformaticsTokyoJapan
  3. 3.Département d’InformatiqueUniversité Libre de BruxellesBrusselsBelgium
  4. 4.Department of Mathematical Informatics, Graduate School of Information Science and TechnologyUniversity of TokyoTokyoJapan
  5. 5.Dept. de MatemáticaUniversidade de AveiroAveiroPortugal

Personalised recommendations