An optimal algorithm for online square detection

  • Authors:
  • Gen-Huey Chen;Jin-Ju Hong;Hsueh-I Lu

  • Affiliations:
  • Department of Computer Science and Information Engineering, National Taiwan University;Department of Computer Science and Information Engineering, National Taiwan University;Department of Computer Science and Information Engineering, National Taiwan University

  • Venue:
  • CPM'05 Proceedings of the 16th annual conference on Combinatorial Pattern Matching
  • Year:
  • 2005

Quantified Score

Hi-index 0.00

Visualization

Abstract

A square is the concatenation of two identical non-empty strings. Let S be the input string which is given character by character. Let m be the (unknown) smallest integer such that the m-th prefix of S contains a square. The online square detection problem is to determine m as soon as the m-th character of S is read. The best previously known algorithm of the online square detection problem, due to Leung, Peng, and Ting, runs in O(mlog2m) time. We improve the time complexity to O(mlog β), where β is the number of distinct characters in the m-th prefix of the input string. It is not difficult to implement our algorithm to run in expected O(m) time.