R
remlostime
Is the sort in <algortithm> the quick_sort, and O(nlogn) ?
remlostime said:Is the sort in <algortithm> the quick_sort, and O(nlogn) ?
Is the sort in <algortithm> the quick_sort
, and O(nlogn) ?
* remlostime:
Yes, sort of. It's guaranteed to be a stable sort,
a) Quick_sort is not O(n log(n)) in worst case complexity, but O( n^2 ). It
is only O(n log(n)) on average with regard to the uniform distribution on
input sequences of length n.
b) The standard permits that std::sort() be implemented as quick_sort, but
you can find other implementations, as well. I have seen introsort, which
is about as fast as quick_sort on average and, in addition, is O(n log(n))
even in the worst case. I think, even the old reference implementation from
HP and SGI may have used introsort, which could have propagated from there.
You can find introsort, for instance, in Stlport and in the standard
library that ships with g++.
c) This is a quality of implementation issue. In my experience, it is _very_
hard to beat std::sort().
Best
Kai-Uwe Bux
std::stable_sort is guaranteed to be a stable sort. Is std::sort also
guaranteed to be a stable sort?
a) Quick_sort is not O(n log(n)) in worst case complexity, but O( n^2 ). It
is only O(n log(n)) on average with regard to the uniform distribution on
input sequences of length n.
b) The standard permits that std::sort() be implemented as quick_sort, but
you can find other implementations, as well. I have seen introsort, which
is about as fast as quick_sort on average and, in addition, is O(n log(n))
even in the worst case. I think, even the old reference implementation from
HP and SGI may have used introsort, which could have propagated from there.
You can find introsort, for instance, in Stlport and in the standard
library that ships with g++.
c) This is a quality of implementation issue. In my experience, it is _very_
hard to beat std::sort().
Best
Kai-Uwe Bux
Neelesh said:std::stable_sort is guaranteed to be a stable sort. Is std::sort also
guaranteed to be a stable sort?
Alf P. Steinbach said:* remlostime:
Not specified.
Yes, sort of. It's guaranteed to be a stable sort, and the complexity is
described as "Approximately N log N". However, what that means (is it a
worst case guarantee, or just an average?) seems to not be defined.
remlostime said:I have learned that you introduct the introsort algorithm,
and how can i use it, which header include it?
I would infer that "approximately" means "average".
I have learned that you introduct the introsort algorithm, and how can
i use it, which header include it?
On a similar subject, did you ever see those TV commercials for
money making
schemes: "Earn an average of up to $4K per month?" That's a magic
number that is both average *and* a best case! What's that all
about? ISTM some government agency should put a stop to such
nonsensical claims.
Gernot Frisch said:If you're the only one with that job, and your income is $4k, then
it's the average _and_ the best case. Thus, this little hint give a
quite detailed description of the job.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.