Popis: |
We introduce a new metric of match, called Cartesian tree matching, which means that two strings match if they have the same Cartesian trees. Based on Cartesian tree matching, we define single pattern matching, multiple pattern matching, and indexing problems. We propose a linear time algorithm for single pattern matching, and randomized linear time algorithms for multiple pattern matching and indexing. We also define three types of periods, called full period, initial period, and general period. We propose O ( n ) time, O ( n log log n ) time, and O ( n log n ) time algorithms for finding all the full periods, initial periods, and general periods of a string of length n, respectively. Our efficient algorithms use a representation of the Cartesian tree, called parent-distance representation. |