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 ...
随机推荐
- 通过select的value值来改变textarea内字体和大小
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Python的50个模块,满足你各种需要
Python具有强大的扩展能力,我列出了50个很棒的Python模块,包含几乎所有的需要:比如Databases,GUIs,Images, Sound, OS interaction, Web,以及其 ...
- Ubuntu 修改hosts
Ubuntu系统的Hosts只需修改/etc/hosts文件,在目录中还有一个hosts.conf文件,刚开始还以为只需要修改这个就可以了,结果发现是需要修改hosts.修改完之后要重启网络.具体过程 ...
- mysql 自动备份导出到sql
创建一个sh文件 vi mysql_auto.sh写入如下代码 导出单个数据库 /www/wdlinux/mysql/bin/mysqldump -uroot -p123456 database &g ...
- python 打印 网格
#/usr/bin/python # -*- coding:utf-8 -*- # width 单个网格有多少个 - 宽度# height 单个网格有多少个 | 高度# lateral 横向有多少个网 ...
- 【65测试20161114】【字符串】【DP】
第一题 复制&粘贴: 文件的内容是一个字符串S,对其进行N次复制&粘贴的操作,第i次操作复制位置Ai和位置Bi之间的所有文字,然后在位置Ci粘贴.这里位置x表示字符串的第x个字符的后面 ...
- <转载>SQL查询数据库各表所占空间
IF OBJECT_ID('tempdb..#TB_TEMP_SPACE') IS NOT NULL DROP TABLE #TB_TEMP_SPACE GO CREATE TABLE #TB_TEM ...
- PostSharp-4.3.22安装包_KeyGen发布
PostSharp-4.3.22安装包_KeyGen发布 请低调使用. 下载相关 PostSharp-4.3.22安装包_KeyGen.part1.rar PostSharp-4.3.22安装包_Ke ...
- ICEM相关
1,几何体建模不用讲(可以不学,因为通常是其他软件导入)在初始分块前,建立part,为建立边界条件使用(这是部分的定义最重要的作用,所以你可以按照不同的情况来定义,划分网格只是块的工作),所以对于三维 ...
- 6、Android之LayoutInflater.inflate()
LayoutInflater.inflate()的作用就是将一个xml定义的布局文件实例化为view控件对象: 与findViewById区别: LayoutInflater.inflate是加载一个 ...