0

I have created a suffix tree in java language. We know that the one of the applications of suffix tree is to search a string from a tree. So my question is, how can I traverse each node of suffix tree in order to find, if a search string exists in suffix tree or not.

Thank you in advance.

Learner11
  • 81
  • 1
  • 1
  • 4
  • 1
    Traversing a suffix tree isn't likely much different than traversing a binary search tree. If you have some code that you've written, could you highlight where you're confused? – Makoto Apr 02 '14 at 02:45
  • The [Wikipedia article](http://en.wikipedia.org/wiki/Suffix_tree) gives a good introduction to suffix trees, including a description of how searching is performed. In addition, you should also spend some time reading the related questions (see list to the right) and the associated answers. I think you'll find your answers there. – Jim Mischel Apr 02 '14 at 13:07

1 Answers1

0

You should post your code...

Im assuming this is a binary tree... heres the pseudocode

findString(RootNode,StringWeWant){
    if RootNode == StringWeWant{
     WERE DONE
    }
    else if RootNode < StringWeWant (string comparison){
     findString(RootNode.rightchild, StringWeWant)
    }
     else{
     findString(RootNode.leftchild,StringWeWant)
    }

}

So as you can see this is a recursive function you can create that tests the root node initially to see if it is the string we want to find. If the root node is less than the string we want, we want to traverse right. If its greater, than traverse left. We can call the same function but pass in the new node we want to compare it to till we find our string we want.

Hope it helps.

asdf
  • 657
  • 1
  • 13
  • 30
  • I am learning algorithms course, I do not understand how to do traversing in a suffix tree. I do not write any code yet. There are many implementations of suffix tree on the internet but there is nothing related to traversing. Based on my understanding a node of a suffix tree may have more than two children. – Learner11 Apr 02 '14 at 03:00
  • So you have a suffix tree of a string and you are searching for a substring of the original string? – asdf Apr 02 '14 at 03:10
  • Yes, I have a suffix tree of a string and I want to search a substring from this tree. – Learner11 Apr 02 '14 at 03:46
  • 2
    No, a suffix tree is a much different thing than a binary search tree. Your answer is not at all appropriate. – Jim Mischel Apr 02 '14 at 13:08