Tuesday, March 19, 2013

How to use SortedDictionary

Leave a Comment

SortedDictionary(Of TKey, TValue)

The SortedDictionary generic class is a binary search tree with O(log n) retrieval, where n is the number of elements in the dictionary. In this respect, it is similar to the SortedList 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 uses less memory than SortedDictionary.
  • SortedDictionary has faster insertion and removal operations for unsorted data: O(log n) as opposed to O(n) for SortedList.
  • If the list is populated all at once from sorted data, SortedList is faster than SortedDictionary.


Code:

Output :

Read More...