Parallel In-Place Merge Sort
drdobbs.com
drdobbs.com
Article said they got 2.2x improvement using their parallel method compared to STL. Trade off was having 100% CPU utilization vs 12.5% with STL.
Or let x be time we need to complete the task:
12.5 * x first (load over time) is less than second 100 * x / 2.2 for the same x.
Or is this an inaccurate comparison?
GPUs are way more parallel, and faster than this too. "clocks about 100x faster than calling std::stable_sort on an i7 Sandy Bridge" http://nvlabs.github.io/moderngpu/mergesort.html
I'm saying their merge sort was likely not actually in-place.
https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-...
Do you know what the time complexity of their merging algorithm is?
As a side note, an optimal merging algorithm is in the paper called "On Optimal and Efficient in Place Merging", and it's too complicated for me to expect it in a standard library implementation. (Although the STL doesn't need to be optimal, I think the sub-optimal linear-time algorithms are also complicated enough to not be used for the standard library, but correct me if I'm wrong.)
> Complexity: It does at most N log^2(N) (where N == last - first) comparisons; if enough extra memory is available, it is N log(N).
I think it's interesting how choice of data structure affects algorithm characteristics.
1. Yes, merge sort is exactly the kind of algorithm you'd use for sorting linked lists
2. No, sorting linked lists is not the primary application of merge sort
For sure, if it doesn't make sense to use a linked list in the first place then linked list merge sort definitely doesn't make sense...
Absolutely. I'm not even sure how you would do such a thing.
I personally have found it interesting when considering the difference between an array of pointers and a linked list, simply because they both have the same overhead but one doesn't require allocating any more memory for a merge sort.
I basically agree with what you say (maybe bar it not being useful knowledge) but I don't think it's worth continuing trying to clarify my initial statement.
The merits and deficits of trading-off O(n)[Memory] growth for 0(log n)^2[Time] growth are worthy of discussion if it is anticipated that people will implement the algorithm in production code. There's a case for looking at it, certainly, on constrained systems, but such systems may not have processors with the execution pipeline sophistication of an Intel i7 quad-core.
Which of course is just a round about way of saying, the article doesn't indicate domains in which the algorithm may be relevant and not relevant.
Saying that, I feel like I'm trying to mislead, though. This requires nlg(n) comparators, so you still have to pay for it somehow. And I doubt we are going to see that many comparators on any piece of kit any time soon. For large n, anyway. (Though, seeing this can be done with a gpu, it does seem that you can hit rather large arrays already.)
[1] http://en.wikipedia.org/wiki/Batcher_odd%E2%80%93even_merges...
If a sorting network (such as Batcher's} requires O(n (log n)^2)[Space] doesn't this sort of defeat the purpose of trying to sort in-place?...since a traditional array copying merge-sort has 0(n)[Space] requirements.
It is algorithms like this that get people very excited about the potential that FPGAs pose, if I understand correctly.
Unless, of course, I completely flubbed my understanding and or math. (Very very possible.)
And then, of course, your point ultimately stands as to why these are not more widely known. For most of us, we have a fixed set of comparators that is very small.
To be a bit snarky, maybe the best piece of hardware to throw first at a sorting problem is a good book on sorting algorithms.
[1] TAoCP: Volume 3 [1978], page 111
I have been going through what is undoubtedly a ridiculous phase of suggesting these books to everyone. I'm doing them in multiple passes where I am mostly skipping exercises for the first pass. Yes, the math is intense. No, they aren't as hard to approach as they have been made out to be.
Anyway, I don't expect to ever master the material, but I learn something every time I open one up.