English

Optimal prefix-suffix queries with applications

Data Structures and Algorithms 2024-11-07 v1

Abstract

We revisit the classic border tree data structure [Gu, Farach, Beigel, SODA 1994] that answers the following prefix-suffix queries on a string TT of length nn over an integer alphabet Σ=[0,σ)\Sigma=[0,\sigma): for any i,j[0,n)i,j \in [0,n) return all occurrences of TT in T[0..i]T[j..n1]T[0\mathinner{.\,.} i]T[j\mathinner{.\,.} n-1]. The border tree of TT can be constructed in O(n)\mathcal{O}(n) time and answers prefix-suffix queries in O(logn+Occ)\mathcal{O}(\log n + \textsf{Occ}) time, where Occ\textsf{Occ} is the number of occurrences of TT in T[0..i]T[j..n1]T[0\mathinner{.\,.} i]T[j\mathinner{.\,.} n-1]. Our contribution here is the following. We present a completely different and remarkably simple data structure that can be constructed in the optimal O(n/logσn)\mathcal{O}(n/\log_\sigma n) time and supports queries in the optimal O(1)\mathcal{O}(1) time. Our result is based on a new structural lemma that lets us encode the output of any query in constant time and space. We also show a new direct application of our result in pattern matching on node-labeled graphs.

Keywords

Cite

@article{arxiv.2411.03784,
  title  = {Optimal prefix-suffix queries with applications},
  author = {Solon P. Pissis},
  journal= {arXiv preprint arXiv:2411.03784},
  year   = {2024}
}

Comments

SOSA 2025

R2 v1 2026-06-28T19:49:57.273Z