msdn敘述:
The SortedDictionary<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 SortedList<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>.less
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>.
譯文:
SortedDictionary<TKey, TValue>泛型類是檢索O(log n)的二叉搜索樹,其中n是字典中的元素數。在這裏,它相似於SortedList<TKey, TValue>泛型類。這兩個類有類似的對象模型,而且都有O(log n)檢索。這兩個類的不一樣之處在於內存的使用以及插入和刪除的速度:
SortedList<TKey, TValue>比SortedDictionary<TKey, TValue >使用更少的內存.
SortedDictionary<TKey, TValue>對於未排序的數據O(log n)具備更快的插入和刪除操做,而SortedList<TKey, TValue>的插入和刪除都是O(n)
若是列表是由已排序的數據一次填充的,那麼SortedList<TKey, TValue>要比SortedDictionary<TKey, TValue>快。this
二者基本敘述:
SortedList:是一個已序的數組(基於KeyValuePair的數組)。基於鍵值排序的鍵值對數組,使用二分查找(log n)檢索key,也可根據index檢索(log 1),add和remove都是o(n)。SortedList爲了保持數組的排序,它會移動位於插入的元素位置以後的全部元素(使用Array.Copy()),因爲每次的插入都會從新排序,致使插入時的性能不好,所以並不推薦使用SortedList排序一個數組。對象
SortedDictionary: 是一個BST,基於二叉查找樹實現,使用二分查找檢索(key),add和remove都是o(log n)blog
二者性能比較:
排序
二者實現比較:
內存
參考:
https://stackoverflow.com/questions/935621/whats-the-difference-between-sortedlist-and-sorteddictionary
https://stackoverflow.com/questions/1376965/when-to-use-a-sortedlisttkey-tvalue-over-a-sorteddictionarytkey-tvalueelement