c# - Dictionary 的时间和空间复杂度是多少?

标签 c# dictionary time-complexity space-complexity

假设我有大小为 N 的数据(即 N 个元素),并且字典是用容量 N 创建的。 的复杂性是什么:

  • 空间--整个字典
  • 时间 -- 添加词条到字典

  • MS 仅显示条目检索接近 O(1)。但是剩下的呢?

    最佳答案

    添加新条目的时间复杂度记录在 Dictionary<T>.Add() 下:

    If Count is less than the capacity, this method approaches an O(1) operation. If the capacity must be increased to accommodate the new element, this method becomes an O(n) operation, where n is Count.

    关于c# - Dictionary 的时间和空间复杂度是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19584938/

    相关文章:

    c# - 使用 C# 创建嵌套的 json

    c# - : Dictionary<string, object> 或 Dictionary<enum,object> 哪个更快/更有效?

    algorithm - 两个嵌套循环的简单算法复杂度

    algorithm - 这是否在 O(N log(N)) 时间内解决了 3SUM?

    c# - 从 Visual Studio 2008 中的 C# 应用程序调用时如何调试 C DLL

    c# - 如何在 C# 中按类型查找 .cs 文件的路径

    c# - EF 代码首先是 : How to delete a row from an entity's Collection while following DDD?

    python - 为什么 issubclass(dict, collections.Mapping) 在 CPython 中为真?

    c# - 枚举和性能

    python - python中heapq.merge的时间复杂度是多少?