Runtime Complexity of .NET Generic Collection
Runtime Complexity of .NET Generic Collection
I had to implement some data structures for my computational geometry class. Deciding whether to implement the data structures myself or using the build-in classes turned out to be a hard decision, as the runtime complexity information is located at the method itself, if present at all. So I went ahead to consolidate all the information in one table, then looked at the source code in Reflector and verified them. Below is my result.
| Internal Implement- ation |
Add/insert | Add beyond capacity | Queue/Push | Dequeue/ Pop/Peek |
Remove/ RemoveAt |
Item[i]/Find(i) | GetEnumerator | MoveNext | |
| List | Array | O(1) to add, O(n) to insert | O(n) | - | - | O(n) | O(1) | O(1) | O(1) |
| LinkedList | Doubly linked list | O(1), before/after given node | O(1) | O(1) | O(1) | O(1), before/after given node | O(n) | O(1) | O(1) |
| Stack | Array | O(1) | O(n) | O(1) | O(1) | - | - | O(1) | O(1) |
| Queue | Array | O(1) | O(n) | O(1) | O(1) | - | - | O(1) | O(1) |
| Dictionary | Hashtable with links to another array index for collision | O(1), O(n) if collision | O(n) | - | - | O(1), O(n) if collision | O(1), O(n) if collision | O(1) | O(1) |
| HashSet | Hashtable with links to another array index for collision | O(1), O(n) if collision | O(n) | - | - | O(1), O(n) if collision | O(1), O(n) if collision | O(1) | O(1) |
| SortedDictionary | Red-black tree | O(log n) | O(log n) | - | - | O(log n) | O(log n) | O(log n) | O(1) |
| SortedList | Array | O(n) | O(n) | - | - | O(n) | O(1) | O(1) | O(1) |
| SortedSet | Red-black tree | O(log n) | O(log n) | - | - | O(log n) | O(log n) | O(log n) | O(1) |
Note:
| Dictionary | Add, remove and item[i] has expected O(1) running time |
| HashSet | Add, remove and item[i] has expected O(1) running time |
Runtime Complexity of .NET Generic Collection的更多相关文章
- The C5 Generic Collection Library for C# and CLI
The C5 Generic Collection Library for C# and CLI https://github.com/sestoft/C5/ The C5 Generic Colle ...
- Your algorithm's runtime complexity must be in the order of O(log n).
Given a sorted array of integers, find the starting and ending position of a given target value. You ...
- C# Collection
数组与集合不同的适用范围: 数组:数组最适用于创建和使用固定数量的强类型化对象. 集合:集合提供更灵活的方式来使用对象组. 与数组不同,你使用的对象组随着应用程序更改的需要动态地放大和缩小. 对于某些 ...
- Instant Complexity - POJ1472
Instant Complexity Time Limit: 1000MS Memory Limit: 10000K Description Analyzing the run-time comple ...
- 三部曲二(基本算法、动态规划、搜索)-1004-Instant Complexity
Instant Complexity Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) ...
- [转]Dynamics AX and Generic collections of .Net
转自:http://blogs.msdn.com/b/emeadaxsupport/archive/2009/04/23/dynamics-ax-and-generic-collections-of- ...
- Instant Complexity(模拟,递归)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1535 Accepted: 529 Description Analyz ...
- Find that single one.(linear runtime complexity0
public class Solution { public int singleNumber(int[] nums) { int temp = 0; for (int i=0;i<nums.l ...
- Generic Interfaces (C# Programming Guide)
https://msdn.microsoft.com/en-us/library/kwtft8ak(v=vs.140).aspx It is often useful to define interf ...
随机推荐
- Apache、NGINX支持中文URL
Apache(32位):安装环境:CentOS 5.6 + Apache 2.2.15安装结果:安装后支持“中文图片.文件名”链接直接打开以下为安装过程:1.下载安装包 wget ftp://ftp. ...
- 5、HTML5列表、块和布局
1.块元素 块元素在显示的时候,通常会以新行开始 如:<h1> <p> <ul> <!-- 块—>注释 <p>hello</p> ...
- 记一次联想A820t救砖线刷
因为是看着教程刷的(有大神放出教程,只管伸手拿来就好啦)但是照着教程做的过程中出现了一些问题还是值得注意的,在这里总结一下,给新手提供一点建议 教程比较长,我放到博客的文件中,需要的自己下载一下.或者 ...
- java给不同步的集合加上同步锁
给非同步的集合加锁: class MyCollections{//创建工具类,提供对外访问方法 public static list synList(List list){ return new My ...
- 【 2013 Multi-University Training Contest 2 】
HDU 4611 Balls Rearrangement 令lcm=LCM(a,b),gcd=GCD(a,b).cal(n,a,b)表示sum(abs(i%a-i%b)),0<=i<n. ...
- ssh框架文件上传下载
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- MS SQL提示列名 'Y' 无效的原因及解决办法
在作项目写MS SQL 存储过程时,需拼接SQL语句字符串,其中有单字符变量,如下图: 如上图执行存储过程是提示“列名‘Y’无效”.经反复测试,原因在用单字符变量连接SQL字符串是必须在引用变量前后各 ...
- C++多线程环境下的构造函数
多线程的环境里,我们总不可避免要使用锁.于是一个常见的场景就是: class ObjectWithLock { private: std::mutex mtx_; SomeResType shared ...
- Integer Break(Difficulty: Easy)
题目: Given a positive integer n, break it into the sum of at least two positive integers and maximize ...
- SQL获取汉字首字母
)) ) as begin ) ) collate Chinese_PRC_CI_AS,letter )) insert into @t(chr,letter) select '吖','A' unio ...