Is SortedDictionary a red-black tree?

后端 未结 5 2039
南笙
南笙 2020-12-17 16:13

I saw several quotes about this on the Internet but no official documentation? Can anyone tell me where I can get information about this?

5条回答
  •  误落风尘
    2020-12-17 16:49

    This is the official documentation from MSDN page;

    The SortedDictionary generic class is a binary search tree with O(log n) retrieval, where n is the number of elements in the dictionary


    Is SortedDictionery a red-black tree?

    Well, I'm not too much fimiliar with red-black tree but I just decompiled SortedDictionary class with dotPeek (which is free) but red-black tree's deletion algorithm and SortedDictionary's Remove() method's code doesn't seems similar. So, my money is for No.

    SortedDictionary keeps its keys always sorted. It allows you to avoid sorting the keys on your own. Its lookup performance is slower than Dictionary. It has advantages if you require a sorted lookup table in memory.

    enter image description here

    Dictionary lookup time:       Close to O(1)
    SortedDictionary lookup time: O(log n) 
    

    Check out more details from here.

提交回复
热议问题