Construction of suffix array on trie

example:

Too many memories, sometimes forgot to forget.
If there is not a non-mind, it is only by means of additional points it!
We define a tree is a past n points n-1 edges of the directed acyclic graph, point numbered 1 to n, where 1 point It is called a root node, except the root node,
each point is exactly the one side (i.e. its side as a starting point).
Each edge of a character (here we actually used is not larger than a non-negative integer representing the different characters 300),
for any point u, u all the edges (i.e., ending at its sides) on character different from each other.
Next we define the past, past the point u corresponding to the root path of u (obviously there is only one) String abbreviated all sides from u to the root according to the sequential ordering of the character after edge stitching sequentially formed on It is r (u).
A contact of the past depends on the tree in the past that it contains all the closest similarity pair. Specifically, we define two points u and v corresponding to the past similarity F (u, v) as follows.
\ (f (u, v)
= Lcp (r (u), r (v)) + Lcs (r (u), r (v)) \) where Lcp (a, b) indicates a string of a and b the length of the longest common prefix, Lcs (a, b) denotes the length of the longest common string suffix a and b.
Contact past a tree is defined as <= u v <= n of the maximum value of f (u, v) satisfies all the 1 <.
Now, given a past tree, please give your contact of the tree past the tree.

answer:

First, all r (u) sort, so, lcp lcp is adjacent r (u) of the RMQ. (The same principle suffix array)
So, after ordering the closer, longer lcp.
Obviously, lcs is the depth of lca.
Therefore, the enumeration lca, namely the tree dfs, each merging all sub-tree, and can ask all the maximum interval of recent RMQ.
Merged with the tree line, maintenance lcp maximum value for each interval, ranking the largest node, ranking lowest node, pushup when considering the maximum and minimum right child of the left child node.
This step is the time complexity of nlogn.

How to consider the sort:

Direct qsort, cmp per half size logn + hash comparison, the total time complexity of nlog ^ 2n.

Consider another approach:

If we know the length of string x the size of relations (ranking), then we will be a string of length x spliced together, you can get 2x the length of the string.
The string of length 2x of the top half of the first key, the second key as a second half of the ranking can be obtained as the length of the string 2x magnitude relationship sorted, and then draw a length of string 2x rankings.
Then, we can continue this process, which will all r (u) order.
Since the ranking is 0 ~ n, radix sort can be employed, each round time complexity is linear, co logn wheel, so the total time complexity is nlogn.
In fact, it is the way suffix array.

Now consider seeking height (that method does not seem to suffix array):

Method a: half + hash.

Method two: multiplying each x up considering a length of 2 ^ i string with a length of up to 2 y ^ i strings are equal.
Can be found, these strings when it is considered a sort doubling, if rankings are equal, then the two strings are equal. The doubling every sort of ranking record on the line.

The total time complexity: \ (O (nlogn) \) .

Code is gone.

Guess you like

Origin www.cnblogs.com/lnzwz/p/11371720.html