简体   繁体   English

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

[英]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)) , where N = 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.

相关问题 带有自定义比较器 function 的 C++ 中 sort() 的时间和空间复杂度是多少? - What is the Time and space complexity of sort() in C++ with custom comparator function? 递归的最坏情况时间复杂度 - Worst case time complexity for recursion 递归除法函数的最坏情况时间复杂度? - Worst-case time complexity of a recursive dividing function? 在 for 循环中 max() function 的最坏情况复杂度是多少? - What is the worst case complexity of max() function inside a for loop? 使用内置的C ++排序功能对2D数组进行排序 - Sorting a 2d array using built in c++ sort function 这个C ++函数的时间复杂度是多少? - What is the time complexity of this C++ function? C ++:使用STL排序以对不同列上的2d整数数组进行排序的时间复杂度 - C++: Time complexity of using STL's sort in order to sort a 2d array of integers on different columns 什么是C ++中strstr()函数的时间复杂度,空间复杂度和算法? - What is the Time Complexity, Space complexity and Algorithm for strstr() function in C++? C++ 标准库中 std::sort() 的时间复杂度是多少? - What is the time complexity of std::sort() in the C++ standard library? 如何找到这个程序的最坏情况复杂度是多少? - How to find what is the worst case complexity of this program?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM