是否有关于 .NET 集合类(Dictionary
、List
等方法的渐近复杂性(big-O 和其他)的资源...)?
我知道 C5 库的文档包含一些有关它的信息(示例),但我也对标准 .NET 集合感兴趣...(PowerCollections 的信息也很好)。
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).
发布评论
评论(6)
本页总结了各种集合类型的一些时间复杂度Java,尽管它们对于 .NET 应该完全相同。
我从该页面获取了表格,并针对 .NET 框架更改/扩展了它们。
另请参阅 SortedDictionary 和 SortedList,详细说明了各种操作所需的时间复杂度。
搜索
、检索和插入、
删除应该与关联集合的插入具有相同的复杂性。
SortedList 对于插入和检索有一些显着的特性。
插入(添加方法):
检索(项目属性):
请注意,就所有操作的复杂性而言,
ArrayList
与List
等效。This page summarises some of the time comlplexities for various collection types with Java, though they should be exactly the same for .NET.
I've taken the tables from that page and altered/expanded them for the .NET framework.
See also the MSDN pages for SortedDictionary and SortedList, which detail the time complexities required for various operations.
Searching
Retrieval and Insertion
Deletion should have the same complexity as insertion for the associated collection.
SortedList has a few notable peculiarities for insertion and retrieval.
Insertion (Add method):
Retrieval (Item property):
Note that
ArrayList
is equivalent toList<T>
in terms of the complexity of all operations.MSDN 列出了这些:
字典<,>
列表
SortedList<,>
(编辑:错误的链接;这是通用版本)SortedDictionary<,>
等。例如:
MSDN Lists these:
Dictionary<,>
List<>
SortedList<,>
(edit: wrong link; here's the generic version)SortedDictionary<,>
etc. For example:
本页介绍了一些主要优点和优点的简短说明。 大多数.NET集合的缺点:
http://geekswithblogs.net/BlackRabbitCoder/archive/2011/06/16/c.net-fundamentals-choosing-the-right-collection-class.aspx
This page presents short notes about some key pros & cons for most .NET Collections :
http://geekswithblogs.net/BlackRabbitCoder/archive/2011/06/16/c.net-fundamentals-choosing-the-right-collection-class.aspx
我一般不知道(刚刚发布的另一个答案可能准确地给出了您所追求的内容) - 但您当然可以使用 ILSpy 反映这个方法和其他方法(对于 FSharp 代码有点尴尬,是的),这最终会产生此函数与 C# 相同:
好吧,这不完全是 C# 术语中的“正确”代码 - 但
while(true)
循环的存在意味着它至少不会是 O(1); 至于它到底是什么......好吧,我的头太痛了,无法找出答案:)I don't know in general (the other answer just posted perhaps gives you exactly what you're after) - but you can reflect this and other methods of course using ILSpy (a little awkward with FSharp code, true) and this eventually yields this function as C#:
Okay so this is not exactly 'proper' code in C# terms - but the presence of the
while(true)
loop implies it can't be O(1) at least; as for what it actually is... well, my head hurts too much to find out :)不存在“集合类的复杂性”这样的事情。 相反,对这些集合的不同操作具有不同的复杂性。 例如,将元素添加到
Dictionary
...而从
Dictionary
检索元素...There's no such thing as "complexity of collection classes". Rather, different operations on these collections have different complexities. For instance, adding an element to a
Dictionary<K, V>
...Whereas retrieving an element from a
Dictionary<K, V>
...文档说它是建立在二叉树上的,并且没有提到跟踪最大元素。 如果文档正确,则意味着它应该是 O(log n)。 集合文档中曾经至少存在一个错误(将数组支持的数据结构称为二叉搜索树),但已得到纠正。
The documentation says it is build on a binary tree, and does not mention tracking the maximum element. If the documentation is correct, that means it should be O( log n). There used to be at least one mistake in the collections documentation (referring to an array-backed data structure as a binary search tree), but that has been corrected.