Rob*_*vey 7 .net c# big-o data-structures
我知道我可以Dictionary
在O(1)时间内使用并检索任意元素.
我知道我可以SortedDictionary
在O(1)时间内得到下一个最高(或最低)元素.但是,如果我想删除第一个值(基于TKey
's IComparable
),该SortedDictionary
怎么办?
我可以使用该.First()
方法检索最小的密钥吗?它的复杂性是什么?它会在O(1),O(log n)还是O(n)时间内运行?
这是SortedDictionary
正确的数据结构吗?
注意:用例是穷人的优先级队列或有序队列.没有开源允许(必须是从头开始的代码,或者已经在.NET 3.5框架中).
SortedDictionary.GetEnumerator被声明为具有O(log n)时间 - 因此First()应该效仿.