English

Fast and Longest Rollercoasters

Data Structures and Algorithms 2019-08-08 v2

Abstract

For k3k\geq 3, a k-rollercoaster is a sequence of numbers whose every maximal contiguous subsequence, that is increasing or decreasing, has length at least kk; 33-rollercoasters are called simply rollercoasters. Given a sequence of distinct numbers, we are interested in computing its maximum-length (not necessarily contiguous) subsequence that is a kk-rollercoaster. Biedl et al. [ICALP 2018] have shown that each sequence of nn distinct real numbers contains a rollercoaster of length at least n/2\lceil n/2\rceil for n>7n>7, and that a longest rollercoaster contained in such a sequence can be computed in O(nlogn)O(n\log n)-time. They have also shown that every sequence of n(k1)2+1n\geq (k-1)^2+1 distinct real numbers contains a kk-rollercoaster of length at least n2(k1)3k2\frac{n}{2(k-1)}-\frac{3k}{2}, and gave an O(nklogn)O(nk\log n)-time algorithm computing a longest kk-rollercoaster in a sequence of length nn. In this paper, we give an O(nk2)O(nk^2)-time algorithm computing the length of a longest kk-rollercoaster contained in a sequence of nn distinct real numbers; hence, for constant kk, our algorithm computes the length of a longest kk-rollercoaster in optimal linear time. The algorithm can be easily adapted to output the respective kk-rollercoaster. In particular, this improves the results of Biedl et al. [ICALP 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 kk-rollercoaster in O(nlog2n)O(n \log^2 n)-time, that is, subquadratic even for large values of knk\leq n. Again, the rollercoaster can be easily retrieved. Finally, we show an Ω(nlogk)\Omega(n \log k) lower bound for the number of comparisons in any comparison-based algorithm computing the length of a longest kk-rollercoaster.

Cite

@article{arxiv.1810.07422,
  title  = {Fast and Longest Rollercoasters},
  author = {Paweł Gawrychowski and Florin Manea and Radosław Serafin},
  journal= {arXiv preprint arXiv:1810.07422},
  year   = {2019}
}
R2 v1 2026-06-23T04:42:50.016Z