arXiv:2609.09064cs.DSSep 2026

Manuscript Offprint

arXiv:2609.09064

Parity and Pattern Detection in Permutation Streams

Mark Braverman, Or Zamir

Abstract

Consider a permutation of [n][n] whose values arrive one at a time. We resolve two questions about the space needed to decide natural properties of such input: First, computing the parity of the permutation requires Θ(n)\Theta(n) bits, even with randomization and constant error, and a constant number of passes. Second, every permutation pattern of length three can be detected deterministically in one pass using O(log⁡n)O(\log n) bits. Together with the 2026 lower bounds of Berendsohn, this completes the classification of fixed permutation patterns; The optimal space complexity is Θ(log⁡n)\Theta(\log n) for monotone patterns and patterns of length at most three, and Θ(n)\Theta(n) for every other pattern. As a consequence, we observe that we can verify BST traversals in streaming with logarithmic memory.

1 Introduction

Consider an input π1,…,πn\pi_1, \ldots, \pi_n that is promised to be a permutation of [n][n]. The values arrive in this order in the streaming model, and an algorithm must decide a property of the permutation while using as little memory space as possible. The promise that every value occurs exactly once can substantially change the space complexity of solving various problems. In particular, problems that are invariant to reordering (e.g. frequency moments) become trivial, and thus we study problems that depend only on the order itself.

Streaming questions about permutations already appeared in early work on distances and measures of sortedness. Cormode, Muthukrishnan, and Sahinalp [CMS01] used embeddings to obtain streaming algorithms for distances between permutations. Ajtai, Jayram, Kumar, and Sivakumar [AJKS02] studied approximate inversion counting, while Gopalan, Jayram, Krauthgamer, and Kumar [GJKK07] studied the longest increasing subsequence and distance to monotonicity. The latter work also proved a linear-space lower bound for computing the longest increasing subsequence exactly, even when the input is a permutation.

Berendsohn [Ber26] studied this setting for permutation pattern detection: A permutation contains a pattern σ\sigma if some subsequence has the same relative order as σ\sigma. For example, an occurrence of 312 consists of positions a<b<ca < b < c with πa>πc>πb\pi_a > \pi_c > \pi_b. For each fixed-length monotone pattern, a standard increasing-subsequence algorithm uses O(log⁡n)O(\log n) bits. For every fixed-length non-monotone pattern of length at least four, Berendsohn proved an Ω(n)\Omega(n) lower bound. For the four remaining patterns,

132,213,231,312,132, \quad 213, \quad 231, \quad 312,

he showed algorithms using O(nlog⁡n)O(\sqrt{n}\log n) or O(nlog⁡n)O(\sqrt{n}\log n) bits of space, but only an Ω(log⁡n)\Omega(\log n) lower bound. Berendsohn conjectured that these patterns require Θ~(n)\widetilde{\Theta}(\sqrt{n}) space, which would imply a surprising trichotomy between three distinct complexity classes.

Another question left open by the above works concerns the parity of a permutation. Let

inv(π)=∣{(i,j):i<j,πi>πj}∣,sgn(π)=(−1)inv(π).\mathrm{inv}(\pi) = |\{(i,j): i < j, \pi_i > \pi_j\}|, \qquad \mathrm{sgn}(\pi) = (-1)^{\mathrm{inv}(\pi)}.

Counting inversions and approximating their number have been studied in the streaming setting [AJKS02]. Computing only their parity asks for a single bit, but the usual type of reductions based on communication complexity encounter a particular difficulty: when a permutation is split into two index sets, not necessarily contiguous, two players can compute its sign with one bit of communication (see e.g. the discussion in [Ber26]).

In this paper we resolve both questions. We show that permutation parity requires linear space, while all patterns of length three admit logarithmic-space algorithms.