有什么方法可以知道 .NET 预定义方法的确切时间复杂度。就像我想知道
的复杂性一样String.Contains()
或
Hashtable.ContainsKey()
Microsoft 是否共享此信息?
最佳答案
是的,在 MSDN 中:)
This method is an O(1) operation.
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/