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

 
http://c-sharp-snippets.blogspot.com/2010/03/runtime-complexity-of-net-generic.html

Runtime Complexity of .NET Generic Collection的更多相关文章

  1. 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 ...

  2. 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 ...

  3. C# Collection

    数组与集合不同的适用范围: 数组:数组最适用于创建和使用固定数量的强类型化对象. 集合:集合提供更灵活的方式来使用对象组. 与数组不同,你使用的对象组随着应用程序更改的需要动态地放大和缩小. 对于某些 ...

  4. Instant Complexity - POJ1472

    Instant Complexity Time Limit: 1000MS Memory Limit: 10000K Description Analyzing the run-time comple ...

  5. 三部曲二(基本算法、动态规划、搜索)-1004-Instant Complexity

    Instant Complexity Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) ...

  6. [转]Dynamics AX and Generic collections of .Net

    转自:http://blogs.msdn.com/b/emeadaxsupport/archive/2009/04/23/dynamics-ax-and-generic-collections-of- ...

  7. Instant Complexity(模拟,递归)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1535   Accepted: 529 Description Analyz ...

  8. 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 ...

  9. Generic Interfaces (C# Programming Guide)

    https://msdn.microsoft.com/en-us/library/kwtft8ak(v=vs.140).aspx It is often useful to define interf ...

随机推荐

  1. 搭建Hadoop2.6.4伪分布式

    准备工作 操作系统 CentOS 7 软件环境 JDK 1.7.0_79 下载地址 SSH,正常来说是系统自带的,若没有请自行搜索安装方法 关闭防火墙 systemctl stop firewalld ...

  2. flash与js交互

    当Flash置于HTML容器中时,经常会遇到Flash与JS的通信问题,例如:JS能否调用Flash中的变量.方法,Flash能否调用JS中的变量.方法等等.答案是肯定的.随着技术的不断发展,解决方案 ...

  3. [移动端]rem适配

    原理:给html根节点设置一个基础font-size值,然后页面的所有元素布局均相对于该font-size值采用rem单位设定.font-size的取值通过js计算. 但字体不用rem单位,原因如下: ...

  4. Android中什么时候使用get和post 以及他们的优缺点!!

    1. get是从服务器上获取数据,post是向服务器传送数据.2. get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到.post是通过H ...

  5. Mallet 使用说明

    Mallet:自然语言处理工具包 发表于128 天前 ⁄ 技术, 科研 ⁄ 评论数 6 ⁄ 被围观 1006 Views+ MALLET是基于java的自然语言处理工具箱,包括分档得分类.句类.主题模 ...

  6. Android中的动画效果

    动画的种类 透明动画alphaAnimation 在代码中配置动画: findViewById(R.id.btnAnimMe).setOnClickListener(new View.OnClickL ...

  7. 6、Concurrent-Mark-Sweep

    1.cms 主要用于年老代垃圾回收 2.这玩意牺牲通吐量换取最短垃圾回收时间 3.有的地方说是四个阶段,有的地方说五个阶段,还有六个阶段的,真相是----我也不知道 四个阶段: Initial mar ...

  8. adb shell

    1.获取进程ID adb shell ps |findstr packagename 2.获取cpu的值 adb shell dumpsys cpuinfo |findstr packagename ...

  9. sqlServer数据库插入数据后返回刚插入记录的自增ID

    insert into tabls1(row1,row1) values('0','0') select @@IDENTITY

  10. A problem about rcssserver3d

    When I enter rcssserver3d to the terminal, the system told me this problem: (SimulationServer) SimCo ...