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 ...
随机推荐
- windows下部署Redis
1.去github上下载最新的项目源码https://github.com/MSOpenTech/redis 2.打开项目文件redis-3.0\msvs\RedisServer.sln 编译所有项目 ...
- js正则表达式大全(3)
正则表达式regular expression详述(一) 正则表达式是regular expression,看来英文比中文要好理解多了,就是检查表达式符 不符合规定!!正则表达式有一个功能十分强大而又 ...
- 获取app安装信息私有api
@class LSApplicationProxy, NSArray, NSDictionary, NSProgress, NSString, NSURL, NSUUID; @interface LS ...
- .htaccess下Flags速查表
Flags是可选参数,当有多个标志同时出现时,彼此间以逗号分隔. 速查表: RewirteRule 标记 含义 描述 R Redirect 发出一个HTTP重定向 F Forbidden 禁止对URL ...
- LeetCode 5 Longest Palindromic Substring manacher算法,最长回文子序列,string.substr(start,len) 难度:2
https://leetcode.com/problems/longest-palindromic-substring/ manacher算法相关:http://blog.csdn.net/ywhor ...
- 认识WCF
WCF 一.什么是WCF? 1.Windows Communication Foundation(WCF)是由微软发展的一组数据通信的应用程序开发接口,可以翻译为Windows通讯接口.它是.NET框 ...
- curl方法post一个数组
$r = $this->curl_post($url, $data);$list = json_decode($r,true); function curl_post($url = '', ...
- Makefile 一点一滴(二)—— 输出文件到指定路径
先来看最简单的 makefile 文件: TestCpp : TestCpp.o g++ -o TestCpp TestCpp.o TestCpp.o : TestCpp.cpp g++ -c Tes ...
- POJ 题目1141 Brackets Sequence(区间DP记录路径)
Brackets Sequence Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 27793 Accepted: 788 ...
- 基于Jenkins + Git的PHP项目编译脚本
本文针对的是了解或已经在使用Jenkins和Git的开发者或团队. 本团队使用了Jenkins作为持续集成平台,Git作为版本管理工具,而本人负责的项目是PHP项目,所谓发布项目就是复制文件. 通常有 ...