Note that there are some explanatory texts on larger screens.

plurals
  1. POInterview Questions relating to Hashtable & Dictionary
    text
    copied!<p>I have been recently drilled in a couple of interviews about Hashtables and when is it neccessary to override the GetHashCode(). The discussion kept going deeper and deeper until I threw in the towel. </p> <p>I am now doing some research to cover everything to be ready for next time.</p> <p>I have found this excellent article that I would like to share: <a href="http://msdn.microsoft.com/en-us/library/ms379571(VS.80).aspx#datastructures20_2_topic5" rel="noreferrer">http://msdn.microsoft.com/en-us/library/ms379571(VS.80).aspx#datastructures20_2_topic5</a></p> <p><strong>1)</strong> Something I don't feel very comfortable with are the fact that Dictionaries are Hash based, but Lists are apparently not. Does that only mean that searching in a List&lt;> and Array[] is linear, while searching in a dictionary or hashtable is constant and therefore much faster? Is this all to it?</p> <p><strong>2)</strong> If I use a class as a key in a dictionary, I need to override GetHashcode() on that class based on any required identification fields to make the instances unique. However it still could happen that both ID fields are equal and the same hashcode would be generated? If this is the case what happens during a collision of the two instances with the same hashcode? </p> <p><strong>3)</strong> How can the collision be resolved? I read in the article about rehashing methodology in case of collision for Hashtable and Chaining for the Dictionary. But I am still not sure how it works exactly as I am not a Math genius. :-\ Can anybody explain it better how it works?</p> <p>Many Thanks, Kave</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload