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. POJ 3414 Pots

    Pots Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status  ...

  2. 从.NET平台调用Win32 API

    MSDN文章<Microsoft Win32 to Microsoft .NET Framework API Map> 介绍了.net 类库对win32的封装 从.NET平台调用Win32 ...

  3. 无边框窗体和timer控件

    一.无边框窗体 1.控制按钮如何制作就是放置可以点击的控件,不局限于使用按钮或是什么别的,只要放置的控件可以点击能触发点击事件就可以了 做的好看一点,就是鼠标移入(pictureBox1_MouseE ...

  4. oracle 函数写法 总结

    1:首先看创建一个函数 给定一个日期,判断是否是休息日. create or replace function test(date_in in date) return int is num int; ...

  5. canvas 时钟+自由落体

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. 在Ubuntu环境把PPT和Word转换为swf文件

    项目需要一个在线浏览文档的功能,于是参照网上的代码写了一份利用Microsoft Office 2010和swftools-2013-04-09-1007.exe转换的程序 思路:调用电脑本机的off ...

  7. 人工智能交互集成在线语音合成能力的Tips

    在线语音合成就是在联网的场景下将文字转换成声音,实现机器向人的声音交互.这个概念应该是比较好理解的,下面就结合官网的Android在线合成的Demo讲解一下合成的流程以及大家经常遇到的一些问题. 到官 ...

  8. 更新centos curl

    centos curl 默认使用nss,而不是openssl 升级curl让curl支持openssl rpm -Uvh http://www.city-fan.org/ftp/contrib/yum ...

  9. 运行html代码

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  10. 【python】错误/异常处理,调试,测试

    try: print('try') r=10/2 print('result is:',r) #发生错误,会执行这部分 except ValueError as e: print('ValueErro ...