zoukankan      html  css  js  c++  java
  • 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

     
    http://c-sharp-snippets.blogspot.com/2010/03/runtime-complexity-of-net-generic.html
  • 相关阅读:
    VS2008下编的程序生成的EXE 在没有安装VS2008的计算机上能运行
    GDI+使用小记
    双缓冲技术绘图
    INI文件格式及其读写
    缩放图片并保存
    按值传递&&按引用传递&&按地址传递
    傻瓜式制作的U盘winpe(支持4G以上U盘)速度超快
    vi 命令大全
    fopen和open的区别
    Linux下Socket网络编程,文件传输,数据传输的C语言例子
  • 原文地址:https://www.cnblogs.com/yonglianglee/p/4541444.html
Copyright © 2011-2022 走看看