-5

Some days ago I wanted to use C++ sort() function to sort an array of strings, but I had a problem!

What algorithm does it use to sort the array? Is it a deterministic one or may it use different algorithms based on the type of the array?

Also, is there a clear time complexity analysis about it?

6
  • 2
    Welcome to Stack Overflow! Please edit your question with a minimal reproducible example or SSCCE (Short, Self Contained, Correct Example) Commented Jan 13, 2016 at 16:43
  • 2
    Have you tried sorting this array of strings? Commented Jan 13, 2016 at 16:44
  • 4
    would it work in less than 1 second(in the worst case)? This is largely architecture dependent. On an i7, maybe, on an Atmega16, absolutely not. Commented Jan 13, 2016 at 16:46
  • ..."but I had a problem" - we're not mind readers. If you want help with a problem you need to describe what you're trying to do, what you actually tried (i.e. provide code), what behaviour you expected, and what behaviour you actually observed. See here: How to ask a good question. If you have no interest in solving that problem, I'm unsure what it has to do with the remainder of your question.
    – WhozCraig
    Commented Jan 13, 2016 at 16:49
  • 1
    You say "I had a problem!" but you never tell us what the problem was. Commented Jan 13, 2016 at 16:51

1 Answer 1

2

Does this function use the same algorithm for sorting numbers array and strings array?

It might or it might not. That is not specified by the standard.

And if we use it to sort an array of strings which the total size of them is less than 100,000 characters, would it work in less than 1 second(in the worst case)?

It might or it might not. It depends on the machine you're running the program on. Even if it will work in less than 1 second in worst case on a particular machine, it would be difficult to prove. But you can get a decent estimation by measuring. A measurement only applies to the machine it was performed, of course.

2
  • Same algorithm: It's not specified by the standard, but it is very likely to use the same algorithm for all sorting. Commented Jan 13, 2016 at 16:48
  • 1
    @MartinBonner All I know that the standard does not mention anything about requiring the algorithm be same for all types. I share a hunch that having a different algorithm would not be worth it, but I couldn't say for certain since I haven't implemented all of the standard libraries.
    – eerorika
    Commented Jan 13, 2016 at 17:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.