I recently woke up in several interviews about Hashtables, and when to override GetHashCode (). The discussion went on deeper and deeper until I threw the towel.
Now I am doing some research to cover everything, to be ready next time.
I found this wonderful article that I would like to share:
http://msdn.microsoft.com/en-us/library/ms379571(VS.80).aspx#datastructures20_2_topic5
1) Something Iām not very comfortable with is that the dictionaries are hash based, but the lists are apparently not. Does this mean that the search in List <> and Array [] is linear, and the search in the dictionary or hash table is constant and therefore much faster? Is that all for this?
2) If I use a class as a key in a dictionary, I need to override GetHashcode () in this class based on any required identification fields to make the instances unique. However, it can happen that both ID fields are equal and the same hash code is generated? If so, what happens during a collision of two instances with the same hash code?
3) How to resolve the conflict? I read in an article about collision rephrasing for Hashtable and Chaining for a dictionary. But I'm still not sure how this works, since I'm not a Math genius.: - \ Can anyone explain how this works?
Thank you very much kava
source
share