繁体   English   中英

在c ++中使用sort()函数对字符串数组进行排序的最坏情况下的时间复杂度是多少?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM