English

Counting distinct (non-)crossing substrings

Data Structures and Algorithms 2025-07-01 v1

Abstract

Let ww be a string of length nn. The problem of counting factors crossing a position - Problem 64 from the textbook ``125 Problems in Text Algorithms'' [Crochemore, Leqroc, and Rytter, 2021], asks to count the number C(w,k)\mathcal{C}(w,k) (resp. N(w,k)\mathcal{N}(w,k)) of distinct substrings in ww that have occurrences containing (resp. not containing) a position kk in ww. The solutions provided in their textbook compute C(w,k)\mathcal{C}(w,k) and N(w,k)\mathcal{N}(w,k) in O(n)O(n) time for a single position kk in ww, and thus a direct application would require O(n2)O(n^2) time for all positions k=1,,nk = 1, \ldots, n in ww. Their solution is designed for constant-size alphabets. In this paper, we present new algorithms which compute C(w,k)\mathcal{C}(w,k) in O(n)O(n) total time for general ordered alphabets, and N(w,k)\mathcal{N}(w,k) in O(n)O(n) total time for linearly sortable alphabets, for all positions k=1,,nk = 1, \ldots, n in ww.

Keywords

Cite

@article{arxiv.2506.22728,
  title  = {Counting distinct (non-)crossing substrings},
  author = {Haruki Umezaki and Hiroki Shibata and Dominik Köppl and Yuto Nakashima and Shunsuke Inenaga and Hideo Bannai},
  journal= {arXiv preprint arXiv:2506.22728},
  year   = {2025}
}
R2 v1 2026-07-01T03:37:31.860Z