Question

If I have a hash table that I know will store 13 items, how can I initialize my table to an appropriate size? I read in my book that the load factor should be at or below 2/3. Does this mean that if I already know that the maximum number of items in my table at any point will be 13, I could do something like:

tableSize = nextPrime((numEntries * 3)/2);

My thinking with the above assignment is that numEntries represents the number 13 and since I know the load factor has to be under 2/3, I find what value I need to make the ratio 2/3.

No correct solution

OTHER TIPS

You can initialize a hashtable as new Hashtable(initialSize, loadFactor)

In simple terms the load factor determines when to allocate more memory to the hashtable

You must be aware that you need not specify memory at initialization to a hashtable unlike arrays. An appropriate loadfactor helps to reduce the overhead of repeated memory allocation.

AFAIK a load factor of 2/3 indicates that the hashtable be allocated with memory when it is 2/3rds full.

Check out : http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Hashtable.html

If you know that the hashtable will be storing 13 entries why not initialize it with

new Hashtable(13) and not worry about the loadfactor which comes into picture when new allocation is needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top