A fast algorithm for finding the positions of all squares in a run-length encoded string

  • Authors:
  • J. J. Liu;G. S. Huang;Y. L. Wang

  • Affiliations:
  • Department of Information Management, Shih Hsin University, Taipei, Taiwan;Department of Computer Science and Information Engineering, National Chi Nan University, Nantou, Taiwan;Department of Information Management, National Taiwan University of Science and Technology, Taipei, Taiwan

  • Venue:
  • Theoretical Computer Science
  • Year:
  • 2009

Quantified Score

Hi-index 5.23

Visualization

Abstract

Squares are strings of the form ww where w is any nonempty string. Main and Lorentz proposed an O(nlogn)-time algorithm for finding the positions of all squares in a string of length n. Based on their result, we show how to find the positions of all squares in a run-length encoded string in time O(NlogN) where N is the number of runs in this string, provided that we do not explicitly compute at all ''trivial squares'' occurring within runs. The algorithm is optimal and its time complexity is independent of the length of the original uncompressed string.