4

I have a suffix array. How to get a string, which suffix array will be equal to the given array?

For example. Let I have this array: [7, 6, 4, 2, 1, 5, 3]. Then the string banana$ is good for me, since get_suffix_array(banana$) == [7, 6, 4, 2, 1, 5, 3].

5
  • You cannot restore a string from its suffix array. Also bapapa$ has the same array. Commented May 17, 2015 at 15:14
  • @AmiTavory, I want to restore any string that has the same suffix array. Commented May 17, 2015 at 15:15
  • Perhaps you should reformulate the title, then. Commented May 17, 2015 at 15:15
  • @AmiTavory, I have edited. Commented May 17, 2015 at 15:17
  • OK, thanks. Much better now. Commented May 17, 2015 at 15:18

1 Answer 1

1

You could build a directed graph from the constraints, then run Topological Sorting, and assign letters to the nodes according to the resulting order.

Start by constructing nodes for the unknown letters, one for each (except for the $).

The first entry will always be the length of the array, because it is $. This gives us nothing.

The following entries, though, each give us constraints.

For example, since the second entry is the length of the array minus one, it must not be larger than any of the other letters. So place an edge from the this node to each of the others. If, however, it would be the length of the array minus two, then there would be a letter smaller than it, but it would be smaller than all the other ones. You can find which is this smaller element from the suffix array, and place a node from it to the last letter, and from the last letter to all the other letters, etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.