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 ...
随机推荐
- DOS常用命令总结
cd 文件夹 如要进入D盘x文件夹,需要先d: 再Enter,然后cd x再Enter. echo \ & pause exit 换行等待按任意键退出,在此操作之前可以做发邮件等动作,bat调 ...
- 洛谷 1004 dp或最大费用流
思路: dp方法: 设dp[i][j][k][l]为两条没有交叉的路径分别走到(i,j)和(k,l)处最大价值. 则转移方程为 dp[i][j][k][l]=max(dp[i-1][j][k-1][l ...
- SYN攻击
一.TCP握手协议 在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接. 第一次握手:建立连接时,客户端发送syn包(syn=j)到服务器,并进入SYN_SEND状态,等待服 ...
- Maven 从svn下载后,pom.xml报错解决方案
Multiple annotations found at this line: - Execution default-testResources of goal org.apache.maven. ...
- 第五篇.Bootstrap 排版
使用bootstrap的排版特性可以创建标题,段落,列表及其它内联元素. 标题:bootstrap中定义了从h1-h6的六种标题样式. 内联子标题: 如果需要向任意一个标题添加一个子标题,只需要加上& ...
- clistctrl失去焦点高亮显示选中行
clistctrl失去焦点高亮显示选中行 响应两个消息 NM_SETFOCUS,NM_KILLFOCUS void CDatabaseParseDlg::OnNMKillfocusListGroup( ...
- 研二下学期做的第一个项目(主要关于datagridview的一些笔记)
首先是行标题列rowheader dataGridView1.TopLeftHeaderCell.Value = "details"; ______________________ ...
- Java之使用NetworkInterface类获得网络接口信息
转:http://www.xuebuyuan.com/1037327.html
- 对客户推荐产品模型+python代码
首先观看数据: l 数据的基本特征用 describe 描述每个基本特征 l 画图画出每个特征的基本统计图 应用import matplotlib.pylab as pl 画图显示 l 关 ...
- 使用eclipse搭建maven项目
一.安装插件 如果安装的eclipse 4.0及以上的版本或是MyEclipse就不用安装插件,可以在工具栏->windows->preferences里面搜索maven,看是否有搜索结果 ...