Find all valid words in a string

Given a String, find out all the valid dictionary words contained in the string.

One Comment

  1. techie007 says:

    Method 1
    1. Create a suffix tree of the String
    http://en.wikipedia.org/wiki/Suffix_tree
    2. Search all the words in dictionary in the Suffix Tree.
    Let N be number of words and L be average length then this will take O(LN) time complexity

    Method 2
    1. If dictionary is already implemented as a trie
    http://en.wikipedia.org/wiki/Trie
    2. We can search all suffixes of string S.
    This can be done in O(Length(S)*Length(S))

    Simple Method
    1. Use a hashtable
    2. Check all substrings in the hashtable in O(2^(Length(S)))

Leave a Reply