I have to write a Dictionary program as a semester project for an undergraduate course on Data Structures and Algorithms, and I am expected to find the most suitable solution (Data Structure) to the problem.
I considered using either a hash table or a trie. I have been suggested to use treaps by someone but have not been able to look into them yet.
My database has about 100k distinct words and their meanings. The basic functionalities the program is expected to provide are insert, update, remove and search a word/definition. If I manage to squeeze in auto-completion and spell correction, that'd be an added bonus.
So, my question is, keeping in mind my requirements, which data structure would be best suited for my purposes. When I say 'best', I am asking for the data structure which has best runtime complexity and low cost (memory requirements).
Also, I wanted to be able to have an algorithm which returned all words starting with the given prefix. For example, say I make a function call dictionary.getWordsStartingWith("fic")
it should return a list of all words that start with fic
such as fiction
, fictitious
,fickle
etc. I know I can do this if I implement my dictionary as a trie, I could do this, but is this possible to do it with a hash table?