Question

I have implemented a suffix tree, which is not compressed. I wanted to know how to solve the problem of finding the longest repreating substring in a string. I know that we have to find the deepest internal node with two children, but how can be code this. Also, how do we know what the longest repeating substring is. I am interested in the code in JAVA. Pls give java implementation. For reference, my TrieNode looks like

class TrieNode{

char ch;
LinkedList<TrieNode> child;

}
Was it helpful?

Solution

It's only the deepest node with 2 children if you store an end of string byte.

To find the longest substring you'll need to do a depth first search, keeping a reference to the deepest node with 2 or more children and it's depth. This is easiest to do with a recursive function.

OTHER TIPS

To find deepest node, one can also do BFS and select node which has maximum level. I think node with maximum level is also the deepest node.then you can check if it has 2 children . else go higher. not sure if this will work though. any comments pps?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top