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/insertAdd beyond capacityQueue/PushDequeue/
Pop/Peek
Remove/ 
RemoveAt
Item[i]/Find(i)GetEnumeratorMoveNext
ListArrayO(1) to add, O(n) to insertO(n)--O(n)O(1)O(1)O(1)
LinkedListDoubly linked listO(1), before/after given nodeO(1)O(1)O(1)O(1), before/after given nodeO(n)O(1)O(1)
StackArrayO(1)O(n)O(1)O(1)--O(1)O(1)
QueueArrayO(1)O(n)O(1)O(1)--O(1)O(1)
DictionaryHashtable with links to another array index for collisionO(1), O(n) if collisionO(n)--O(1), O(n) if collisionO(1), O(n) if collisionO(1)O(1)
HashSetHashtable with links to another array index for collisionO(1), O(n) if collisionO(n)--O(1), O(n) if collisionO(1), O(n) if collisionO(1)O(1)
SortedDictionaryRed-black treeO(log n)O(log n)--O(log n)O(log n)O(log n)O(1)
SortedListArrayO(n)O(n)--O(n)O(1)O(1)O(1)
SortedSetRed-black treeO(log n)O(log n)--O(log n)O(log n)O(log n)O(1)

Note:

DictionaryAdd, remove and item[i] has expected O(1) running time
HashSetAdd, remove and item[i] has expected O(1) running time

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

转载于:https://www.cnblogs.com/yonglianglee/p/4541444.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值