C # dictionary, collection, time complexity of the list

List listing the order linear table, Add operation is O (1) or O (N), because List is the dynamic expansion, before the non-expansion, which Add operation is O (1), and at the time of expansion, the Add operation is O (N) is. Contains method thereof, in accordance with a linear search, which is a complexity of O (n).

SortedList list is an ordered linear table, Add operations is O (n), which Contains method is to find the retrieving elements by half, and therefore the complexity is O (lg n), which Containskey methods also find retrieving elements by half, the complexity is O (lg n), ContainsValue element is a linear search complexity is O (n).

HashSet collection is not duplicates comprising unordered hash table (non-linear), which itself is a one-dimensional array, but the two-dimensional chain structure (extension: one-dimensional array of size N is always a power of 2). Add operation is O (1) or O (N), because the same collection class List. Contains method is O (1).

SortedSet collection is based on a red-black tree implementation, the Add method is O (lg n), Contains method is O (lg n).

Dictionary dictionary class is the hash table, Add operation is O (1) or O (N), the principle above. Containskey which is O (1), because the hash to search through the elements, rather than through the elements. The method ContainsValue time complexity is O (N), because the internal value by iterating to find key, rather than by a lookup hash. Item [Key] The key to retrieve the property value, the time complexity is O (1).

SortedDictionary dictionary category is based on a balanced binary tree-implemented Add method is O (lg n), ContainsKey method is O (lg n), and ContainsValue method is O (n).

Guess you like

Origin www.cnblogs.com/wccfsdn/p/11945454.html