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/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) |
Dictionary | Add, remove and item[i] has expected O(1) running time |
HashSet | Add, remove and item[i] has expected O(1) running time |
相关文章推荐
- 求职-如何伪装一份cs的简历
- eclipse-ubuntu14.04图标替换不掉的问题
- Modern OpenGL用Shader拾取VBO内单一图元的思路和实现(3)
- 虚拟机中 CentOS 网络配置图解
- LDA 主题模型解析
- I/O复用知识前瞻
- Python 3 -Functions
- 一步一步源码编译最新版LAMP平台(二)
- 内核调度进程的机制
- 闲说性能测试
- iostat命令详解
- Linux vmstat命令实战详解
- 嵌入式软件开发培训笔记——Linux下SQLite3数据库编程
- JS中stopPropagation函数停止事件传播
- Nginx(1)------- Nginx支持热部署的原理
- 性能更好的js动画实现方式——requestAnimationFrame
- phpstorm配置Xdebug进行调试PHP教程
- 输出Bag中的所有记录为一个json数组---精通android、IOS App应用服务程序开发
- 别再管什么用户体验了(转)
- 使用PHP实现简易词典查询功能