Quote:
Originally Posted by cannabusto
Would anyone mind explaining hash tables to me like I'm 5?
A hash table is basically an associative array that is optimized for faster look-up times. Say you had an array that mapped people to their phone numbers:
PhoneNumbers["John Smith"] = 555-453-4567
PhoneNumbers["Abigail Adams"] = 555-973-4170
PhoneNumbers["Michael Turner"] = 555-779-0340
...
Imagine there are thousands of entries. If you want the entry for "Michael Turner", you're going to have to search through the keys to find it's index. There could be thousands and thousands of keys, so this might take a while.
What a hash table does, instead, is to use some function to compute the index for each key. This way, when it's time to look up "Michael Turner", you just run the hash function to find his index and then access it directly, without searching through the array. Behind the scenes, your array would look something like this:
PhoneNumbers[d131dd02c5e6eec4] = 555-453-4567
PhoneNumbers[55ad340609f4b302] = 555-973-4170
PhoneNumbers[d8823e3156348f5b] = 555-779-0340
And your hash function would work like this:
SomeHashFunction("Michael Turner") -> returns d8823e3156348f5b
This method also allows for insertions/deletions into the array without worrying about sorting/reordering. For more:
http://en.wikipedia.org/wiki/Hash_table