views:

35

answers:

2

I am preparing for my interview and came across this question:

Consider that i have 1000,000 words and i want to create a dictionary . The data structure i can use is Map or B+ trees . But on what criteria should i write my hashcode(), so that the retrieval can be fast.

would welcome everybody views...

+2  A: 

I would use neither and store the dictionary as a Patricia trie instead.

It also uses less memory since you're not storing all the common prefixes of all strings separately.

polygenelubricants
thanks , Patricia trie is very interesting. Good find for me to explore :-)
harshit
+1  A: 

In the "old days" (1980's) we tended to use B* (or B*+) trees and were very picky about hitting the disk, but nowadays 1,000,000 keys is nothing to fit in memory, so stick it in a dict and be done with it.

And tell this to your interviewer: memory is close to free compared to the cost of developers. The amount of time you spend trying to be clever on this will never be recovered in efficiency by anything you can come up. If they don't understand why that's true, then ... eh.

Peter Rowell