Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Framework Time complexity in the documentation [duplicate]

Are there any resources about the asymptotic complexity (big-O and the rest) of methods of .NET collection classes (Dictionary<K,V>, List<T> etc...)?

I know that the C5 library's documentation includes some information about it (example), but I'm interested in standard .NET collections too... (and PowerCollections' information would also be nice).

like image 958
Igor Brejc Avatar asked May 12 '09 09:05

Igor Brejc


1 Answers

MSDN Lists these:

  • Dictionary<,>
  • List<>
  • SortedList<,> (edit: wrong link; here's the generic version)
  • SortedDictionary<,>

etc. For example:

The SortedList(TKey, TValue) generic class is a binary search tree with O(log n) retrieval, where n is the number of elements in the dictionary. In this, it is similar to the SortedDictionary(TKey, TValue) generic class. The two classes have similar object models, and both have O(log n) retrieval. Where the two classes differ is in memory use and speed of insertion and removal:

SortedList(TKey, TValue) uses less memory than SortedDictionary(TKey, TValue).

SortedDictionary(TKey, TValue) has faster insertion and removal operations for unsorted data, O(log n) as opposed to O(n) for SortedList(TKey, TValue).

If the list is populated all at once from sorted data, SortedList(TKey, TValue) is faster than SortedDictionary(TKey, TValue).

like image 188
Marc Gravell Avatar answered Sep 20 '22 08:09

Marc Gravell