c# - .NET BCL API 或框架方法的时间复杂度

标签 c# .net algorithm complexity-theory

有什么方法可以知道 .NET 预定义方法的确切时间复杂度。就像我想知道

的复杂性一样
String.Contains() 

 Hashtable.ContainsKey()

Microsoft 是否共享此信息?

最佳答案

是的,在 MSDN 中:)

  1. Hashtable.ContainsKey Method :

This method is an O(1) operation.

  1. Enumerable.Contains Method (IEnumerable, TSource) :

If the type of source implements ICollection, the Contains method in that implementation is invoked to obtain the result. Otherwise, this method determines whether source contains the specified element.

Enumeration is terminated as soon as a matching element is found.

因此,对于 String,它将是 O(n)。

关于c# - .NET BCL API 或框架方法的时间复杂度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5563150/

相关文章:

algorithm - 组合和深度优先搜索解决方案

c# - 程序集是否维护其目录结构?

c# - 从 excel 文件中检索标量

c# - 确保所有线程退出

c# - RegLoadAppKey 在 32 位操作系统上运行良好,在 64 位操作系统上失败,即使两个进程都是 32 位的

c# - XML 字符串数组反序列化

c# - 覆盖配置设置

algorithm - 检查指定范围内连续奇数的素数

c# - 多个返回案例的条件 ifs

c++ - 查找总和等于 k ​​的子集的数量