不同的数据结构和复杂性

时间:2011-01-06 13:37:29

标签: language-agnostic data-structures reference complexity-theory

我知道存在 wiki link ,它具有不同的数据结构。

我想知道是否有一个地方可以以简洁的表格格式(供参考)获得复杂性(插入,删除,更新等)。

2 个答案:

答案 0 :(得分:0)

您在问题中链接到的页面包含许多数据结构的列表。每个页面都详细说明了特定的数据结构。我知道您希望以现成的格式进行比较表,但由于它似乎不存在,因此您可以通过浏览各种页面轻松地将它们组合在一起。例如,数组中各种算法的比较给出here,对于b-tree here。所以可能需要一些工作才能将它们全部编译成一个简单的引用。嗯...也许正在制作博客文章。

答案 1 :(得分:0)

这是维基百科:Worst-case analysis of data structures

+----------------------+----------+------------+----------+--------------+
|                      |  Insert  |   Delete   |  Search  | Space Usage  |
+----------------------+----------+------------+----------+--------------+
| Unsorted array       | O(1)     | O(1)       | O(n)     | O(n)         |
| Value-indexed array  | O(1)     | O(1)       | O(1)     | O(n)         |
| Sorted array         | O(n)     | O(n)       | O(log n) | O(n)         |
| Unsorted linked list | O(1)*    | O(1)*      | O(n)     | O(n)         |
| Sorted linked list   | O(n)*    | O(1)*      | O(n)     | O(n)         |
| Balanced binary tree | O(log n) | O(log n)   | O(log n) | O(n)         |
| Heap                 | O(log n) | O(log n)** | O(n)     | O(n)         |
| Hash table           | O(1)     | O(1)       | O(1)     | O(n)         |
+----------------------+----------+------------+----------+--------------+

 * The cost to add or delete an element into a known location in the list
   (i.e. if you have an iterator to the location) is O(1).
   If you don't know the location, then you need to traverse the list to the location of deletion/insertion, which takes O(n) time. 
** The deletion cost is O(log n) for the minimum or maximum, O(n) for an arbitrary element.