Solved

# stl sort

Posted on 2011-09-13
335 Views
Hi there,

I am interested in finding out the amount of memory that is being used by stl's sort.

Thanks,
0
Question by:zizi21

LVL 53

Accepted Solution

Infinity08 earned 167 total points
ID: 36528144
The memory complexity of the std::sort algorithm is not defined in the standard, so there's no way to be sure what the memory complexity is for a given implementation (apart from reading the implementation's documentation).

However, I'd expect the memory complexity to be O(1) or O(log n).

You'll note that the SGI implementation (cfr the link you posted) mentions that the introsort algorithm is used. The introsort algorithm has an O(log n) memory complexity.
0

LVL 40

Assisted Solution

evilrix earned 167 total points
ID: 36528148
Since the standard STL sort is generally a quick sort the worse case memory usage will be O(logn).

http://en.wikipedia.org/wiki/Quicksort
0

LVL 6

Assisted Solution

theKashyap earned 166 total points
ID: 36538093
As someone mentioned it's implementation dependent.
Find out what's teh implementation (STL code would anyway be available) and then refer to the table in this page, it has the memory complexity described for most common algorithms.

Or did you mean you want a real number, say in KB?
- For that easiest is to run with a profiler (E.g. Rational Quantify)
- Or you can write some code like this or this depending on your needs.
0

Author Closing Comment

ID: 36540708
Thanks for the help..
0

## Featured Post

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.