Solved

stl sort

Posted on 2011-09-13
4
341 Views
Last Modified: 2012-05-12
Hi there,

I am interested in finding out the amount of memory that is being used by stl's sort.
I have read the link :http://www.sgi.com/tech/stl/sort.html and there is mention about complexity but nothing about memory .

Could anyone please direct me to the link ?

Thanks,
0
Comment
Question by:zizi21
4 Comments
 
LVL 53

Accepted Solution

by:
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

by:evilrix
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

by:theKashyap
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

by:zizi21
ID: 36540708
Thanks for the help..
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question