Solved

stl sort

Posted on 2011-09-13
4
335 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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++.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now