您的位置:首页 > 其它

Runtime Complexity of .NET Generic Collection

2015-05-31 05:09 274 查看

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: