编程语言
首页 > 编程语言> > c#-.NET BCL API或框架方法的时间复杂度

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

作者:互联网

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

String.Contains() 

要么

 Hashtable.ContainsKey()

Microsoft是否共享此信息?

解决方法:

是的,在MSDN中:)

> Hashtable.ContainsKey Method

This method is an O(1) operation.

> 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).

标签:complexity-theory,c,net,algorithm
来源: https://codeday.me/bug/20191102/1993828.html