Reputation: 75
what is best way how to find word in big dictionary?
I have one word for example dog
and i want to check, if is this word in my dictionary - only true, false
. Is there any better way then binary search
?
Java pls :-)
Upvotes: 0
Views: 404
Reputation: 11930
You can use a HashSet
, to check for a word existence in O(1):
Set<String> dict = new HashSet<String>();
dict.add("dog");
dict.add("cat");
System.out.println(dict.contains("dog")); // true
If you want to create you own structures, you can also have a look at Tries and DAWGs.
Upvotes: 2