Author | Message |
---|---|
dchou4
Posts: 4
|
Posted 09:37 Apr 21, 2018 |
So if we already know that there are 11 keys and our hash table has only a size of 11. With the load factor threshold being 50%. Is there any reason we can't just rehash from the beginning. Start with a table size of 22 and a mod of 22. |
kknaur
Posts: 540
|
Posted 10:48 Apr 21, 2018 |
I mean technically you could do this... and to keep going with your thought, what if we start the table size at 33 instead of 22, or 55 instead of 33...and on and on it goes. The idea is that your Hash Table should dynamically grow as you continue to add more and more items to it, and the way you make this work is by rehashing. It's the same concept as an ArrayList, your underlying array starts at an initial capacity and will resize as you add more and more items to it. Think long term when you try to implement these assignments. The data sample you are testing with may be very small, but what happens if the data set was very large, or you didn't have prior knowledge about the size of the data? It doesn't matter if the assignment only covers a small sample of data, you should still try to implement the assignment in terms of how your program might be used in a live production environment.
|