How the Dictionary is internally maintained?

前端 未结 4 728
广开言路
广开言路 2021-01-17 16:57

When i say

Dictionary

is it equivalent to two different arrays such as:

int[] keys =new int[] { 1, 2, 3          


        
4条回答
  •  抹茶落季
    2021-01-17 17:34

    It is hashtable. For each key Dictionary calculates its hash code, and uses this as a pointer to place where value should reside. If there are two keys matching the same hash code, such situation is called collision and internally for this special case Dictionary uses binary tree.

    Algorithmic complexity of Dictionary(hashtable) is O(1) and in worst case O(log(N)) (worst case means we deal only with collisions), where N is a number of elements in Dictionary.

提交回复
热议问题