Represent your string that way, in a Suffix Tree.
Make searching easier and make use of your study of Automata and Regular Expressions ;)
Brief Explanation:
As I mentioned above, "make use of Automata...", let me explain briefly by example:
The string "bananas", if you wanna extract a substring out of, let's say u wanna choose a string starting with "n" .. you have two choices then...either "nanas" or "nas"
so let's imagine a graph structure, standing at letter (node) "n" and u wanna check what's possible next letter..it's "a" in both choices... then from "a" you go either to another "n" or "s" ... the other "n" goes to "a" then "s"
But, could u observe something, i said "it's 'a' in both choices" why don't concatenate the "a" to "n" then ?
exactly that what we gonna do... (NOTE: suffix tree nodes are not letters, path from root to a node is a substring, edges are labeled with substrings)
Read more here
Uses:
- Find substrings
- Find Occurences of a pattern
- find all strings that contain a pattern
- Find the longest substring of that appears at least m > 1 times
- Find the longest common substring of two strings
al salamo 3alikom wa ra7mato ALLAH wa barkatoh
No comments:
Post a Comment