views:

54

answers:

3

Hii ,

I ran across a interview question of implementing a dictionary that can implement the features of auto-completion , auto - correction , spell check etc...

I actually wanted to know which data structure is the best for implementing a dictionary and how one approaches the above required features...

Any links that guide me on this are welcome...

+1  A: 

There is just the same answer for this kind of problem: a Trie. Take a look here..

Also suffix trees (or Patricia Trees) can be useful for this purposes..

Jack
Doesn't really work for auto-correction.
Let_Me_Be
For auto-correction you have to use spell-checking. But I don't think it is a matter of data-structures. More a matter of algorithms that works on data-structures.. I think they may work on tries anyway. Actually if you have a dictionary (abstracting from implementation) I think you should work out on hamming distance between what user inserted and plausible words similar to that.
Jack
+1  A: 

Tries are a common structure for this. They are a special case of finite-state automata, which have also been used for dictionary construction and spell checking.

larsmans
A: 

You can get auto-completion with any sorted container, for example a set of strings:

#include <limits>
#include <set>
#include <string>
#include <vector>

int main()
{
    std::set<std::string> words = {"foo", "bar", "barber", "baz", "quux"};

    std::string starting_with = "ba";
    auto lower = words.lower_bound(starting_with);
    auto upper = words.upper_bound(starting_with + std::numeric_limits<char>::max());

    std::vector<std::string> suggested_words(lower, upper);
}
FredOverflow