Dictionary search method

We use a dictionary to lookup the nodes here because it’s more efficient than a double nested for loop. Fair enough, but I’m curious; what algorithm does a Dictionary use under the hood that makes it so efficient for searching?

Dictionaries hashes the keys and use those as indexes to a hash table. You can check out this StackOverflow answer as well as the accepted answer in that post.

Essentially, the hash code of the key is used to compute the index into the hashtable and the value is retrieved from that location. I am leaving out info about collisions, etc. but you should find all the info in the link above

Thanks!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms