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