![](/img/trans.png)
[英]What is the Time and space complexity of sort() in C++ with custom comparator function?
[英]What is the worst case time complexity of sorting an array of strings using sort() function in c++?
例
string input[3]={"Earth","Mars","Mercury"};
sort(input,input+3);
在C ++ 11之前,复杂度平均为N.log(N)
,最坏情况下的复杂度取决于您的标准库实现。 对于该语言的更高版本,该标准要求复杂度为N.log(N)
。
来自https://en.cppreference.com/w/cpp/algorithm/sort :
复杂
O(N·log(N)) ,其中
N = std::distance(first, last)
平均N = std::distance(first, last)
比较。 (直到C ++ 11) O(N·log(N)) ,其中N = std::distance(first, last)
比较。 (自C ++ 11起)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.