Document Open Access Logo

Fast and Longest Rollercoasters

Authors Paweł Gawrychowski, Florin Manea, Radosław Serafin

Thumbnail PDF


  • Filesize: 0.67 MB
  • 17 pages

Document Identifiers

Author Details

Paweł Gawrychowski
  • Institute of Computer Science, University of Wrocław, Poland
Florin Manea
  • Kiel University, Germany
Radosław Serafin
  • Institute of Computer Science, University of Wrocław, Poland

Cite AsGet BibTex

Paweł Gawrychowski, Florin Manea, and Radosław Serafin. Fast and Longest Rollercoasters. In 36th International Symposium on Theoretical Aspects of Computer Science (STACS 2019). Leibniz International Proceedings in Informatics (LIPIcs), Volume 126, pp. 30:1-30:17, Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2019)


For k >= 3, a k-rollercoaster is a sequence of numbers whose every maximal contiguous subsequence, that is increasing or decreasing, has length at least k; 3-rollercoasters are called simply rollercoasters. Given a sequence of distinct real numbers, we are interested in computing its maximum-length (not necessarily contiguous) subsequence that is a k-rollercoaster. Biedl et al. (2018) have shown that each sequence of n distinct real numbers contains a rollercoaster of length at least ceil[n/2] for n>7, and that a longest rollercoaster contained in such a sequence can be computed in O(n log n)-time (or faster, in O(n log log n) time, when the input sequence is a permutation of {1,...,n}). They have also shown that every sequence of n >=slant (k-1)^2+1 distinct real numbers contains a k-rollercoaster of length at least n/(2(k-1)) - 3k/2, and gave an O(nk log n)-time (respectively, O(n k log log n)-time) algorithm computing a longest k-rollercoaster in a sequence of length n (respectively, a permutation of {1,...,n}). In this paper, we give an O(nk^2)-time algorithm computing the length of a longest k-rollercoaster contained in a sequence of n distinct real numbers; hence, for constant k, our algorithm computes the length of a longest k-rollercoaster in optimal linear time. The algorithm can be easily adapted to output the respective k-rollercoaster. In particular, this improves the results of Biedl et al. (2018), by showing that a longest rollercoaster can be computed in optimal linear time. We also present an algorithm computing the length of a longest k-rollercoaster in O(n log^2 n)-time, that is, subquadratic even for large values of k <= n. Again, the rollercoaster can be easily retrieved. Finally, we show an Omega(n log k) lower bound for the number of comparisons in any comparison-based algorithm computing the length of a longest k-rollercoaster.

Subject Classification

ACM Subject Classification
  • Theory of computation → Design and analysis of algorithms
  • Theory of computation → Data structures design and analysis
  • sequences
  • alternating runs
  • patterns in permutations


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Alok Aggarwal and Maria M. Klawe. Applications of generalized matrix searching to geometric algorithms. Discrete Applied Mathematics, 27(1-2):3-23, 1990. Google Scholar
  2. Alok Aggarwal, Maria M. Klawe, Shlomo Moran, Peter W. Shor, and Robert E. Wilber. Geometric Applications of a Matrix-Searching Algorithm. Algorithmica, 2:195-208, 1987. Google Scholar
  3. David Aldous and Persi Diaconis. Longest Increasing Subsequences: From Patience Sorting to the Baik-Deift-Johansson Theorem. Bulletin of the American Mathematical Society, 36:413-432, 1999. Google Scholar
  4. Sergei Bespamyatnikh and Michael Segal. Enumerating longest increasing subsequences and patience sorting. Information Processing Letters, 76(1):7-11, 2000. Google Scholar
  5. Therese C. Biedl, Ahmad Biniaz, Robert Cummings, Anna Lubiw, Florin Manea, Dirk Nowotka, and Jeffrey Shallit. Rollercoasters and Caterpillars. In ICALP, volume 107 of LIPIcs, pages 18:1-18:15. Schloss Dagstuhl - Leibniz-Zentrum fuer Informatik, 2018. Google Scholar
  6. Therese C. Biedl, Timothy M. Chan, Martin Derka, Kshitij Jain, and Anna Lubiw. Improved Bounds for Drawing Trees on Fixed Points with L-Shaped Edges. In Graph Drawing and Network Visualization - 25th International Symposium, GD 2017, Revised Selected Papers, volume 10692 of Lecture Notes in Computer Science, pages 305-317. Springer, 2017. Google Scholar
  7. Bernard Chazelle. A Functional Approach to Data Structures and Its Use in Multidimensional Searching. SIAM J. Comput., 17(3):427-462, 1988. Google Scholar
  8. Maxime Crochemore and Ely Porat. Fast Computation of a Longest Increasing Subsequence and Application. Information and Computation, 208(9):1054-1059, 2010. Google Scholar
  9. Paul Erdős and George Szekeres. A combinatorial problem in geometry. Compositio Mathematica, 2:463-470, 1935. Google Scholar
  10. Michael L. Fredman. On computing the length of longest increasing subsequences. Discrete Mathematics, 11(1):29-35, 1975. Google Scholar
  11. Hania Gajewska and Robert Endre Tarjan. Deques with Heap Order. Information Processing Letters, 22(4):197-200, 1986. Google Scholar
  12. P. Gawrychowski, F. Manea, and R. Serafin. Fast and Longest Rollercoasters. arXiv, 2018. URL:
  13. James W. Hunt and Thomas G. Szymanski. A Fast Algorithm for Computing Longest Common Subsequences. Communications of the ACM, 20(5):350-353, 1977. Google Scholar
  14. Sergey Kitaev. Patterns in Permutations and Words. Springer, 2011. Google Scholar
  15. S. Linton, N. Ruškuc, and V. Vatter, editors. Permutation Patterns. London Mathematical Society Lecture Note Series, vol. 376, Cambridge, 2010. Google Scholar
  16. Dan Romik. The Surprising Mathematics of Longest Increasing Subsequences. Cambridge, 2015. Google Scholar
  17. Craige Schensted. Longest increasing and decreasing subsequences. Canadian Journal of Mathematics, 13:179-191, 1961. Google Scholar
  18. J. Michael Steele. Variations on the monotone subsequence theme of Erdős and Szekeres. In David Aldous, Persi Diaconis, Joel Spencer, and J. Michael Steele, editors, Discrete Probability and Algorithms, pages 111-131. Springer New York, 1995. Google Scholar
  19. Xiaoming Sun and David P. Woodruff. The Communication and Streaming Complexity of Computing the Longest Common and Increasing Subsequences. In Proceedings of the Eighteenth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA '07, pages 336-345. Society for Industrial and Applied Mathematics, 2007. Google Scholar
  20. Alexander Tiskin. Fast Distance Multiplication of Unit-Monge Matrices. Algorithmica, 71(4):859-888, 2015. Google Scholar
Questions / Remarks / Feedback

Feedback for Dagstuhl Publishing

Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail