stable-sort

which algorithm can do a stable in-place binary partition with only O(N) moves?

帅比萌擦擦* 提交于 2019-11-28 08:19:53
I'm trying to understand this paper: Stable minimum space partitioning in linear time. It seems that a critical part of the claim is that Algorithm B sorts stably a bit-array of size n in O(nlog 2 n) time and constant extra space, but makes only O(n) moves. However, the paper doesn't describe the algorithm, but only references another paper which I don't have access to. I can find several ways to do the sort within the time bounds, but I'm having trouble finding one that guarantees O(N) moves without also requiring more than constant space. What is this Algorithm B? In other words, given

Stable separation for two classes of elements in an array

删除回忆录丶 提交于 2019-11-27 15:15:46
Consider the following problem. We are given an array of elements belonging to one two classes: either red or blue. We have to rearrange the elements of the array so that all blue elements come first (and all red elements follow). The rearrangement must be done is stable fashion, meaning that the relative order of blue elements must be preserved (same for red ones). Is there a clever algorithm that would perform the above rearrangement in-place? A non-in place solution is, of course, straightforward. An obvious in-place solution would be to apply any stable sorting algorithm to the array.

Stabilizing the standard library qsort?

☆樱花仙子☆ 提交于 2019-11-27 04:50:24
I'm assuming that the good old qsort function in stdlib is not stable, because the man page doesn't say anything about it. This is the function I'm talking about: #include <stdlib.h> void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); I assume that if I change my comparison function to also include the address of that which I'm comparing, it will be stable. Is that correct? Eg: int compareFoos( const void* pA, const void *pB ) { Foo *pFooA = (Foo*) pA; Foo *pFooB = (Foo*) pB; if( pFooA->id < pFooB->id ) { return -1; } else if( pFooA->id > pFooB->id ) {

which algorithm can do a stable in-place binary partition with only O(N) moves?

我怕爱的太早我们不能终老 提交于 2019-11-27 02:09:02
问题 I'm trying to understand this paper: Stable minimum space partitioning in linear time. It seems that a critical part of the claim is that Algorithm B sorts stably a bit-array of size n in O(nlog 2 n) time and constant extra space, but makes only O(n) moves. However, the paper doesn't describe the algorithm, but only references another paper which I don't have access to. I can find several ways to do the sort within the time bounds, but I'm having trouble finding one that guarantees O(N) moves

Stable accumarray in MATLAB

江枫思渺然 提交于 2019-11-26 21:03:47
MATLAB's built-in function accumarray accepts a function fun as a fourth argument. A = accumarray(subs,val,sz,fun); This applies fun to each subset of elements in val that have identical subscripts in subs . The documentation however states: If the subscripts in subs are not sorted with respect to their linear indices, fun should not depend on the order of the values in its input data. How can we implement a stable version of accumarray , which doesn't have this limitation, but will guarantee that the subsets adopt the same order as given by val ? Example: subs = [1:10,1:10]; val = 1:20;

Is python&#39;s sorted() function guaranteed to be stable?

心已入冬 提交于 2019-11-26 11:21:46
The documentation doesn't guarantee that. Is there any other place that it is documented? I'm guessing it might be stable since the sort method on lists is guaranteed to be stable (Notes 9th point: "Starting with Python 2.3, the sort() method is guaranteed to be stable"), and sorted is functionally similar. However, I'm not able to find any definitive source that says so. Purpose: I need to sort based on a primary key and also a secondary key in cases where the primary key is equal in both records. If sorted() is guaranteed to be stable, I can sort on the secondary key, then sort on the

Stabilizing the standard library qsort?

那年仲夏 提交于 2019-11-26 11:21:39
问题 I\'m assuming that the good old qsort function in stdlib is not stable, because the man page doesn\'t say anything about it. This is the function I\'m talking about: #include <stdlib.h> void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); I assume that if I change my comparison function to also include the address of that which I\'m comparing, it will be stable. Is that correct? Eg: int compareFoos( const void* pA, const void *pB ) { Foo *pFooA = (Foo*)

Stable accumarray in MATLAB

廉价感情. 提交于 2019-11-26 07:50:05
问题 MATLAB\'s built-in function accumarray accepts a function fun as a fourth argument. A = accumarray(subs,val,sz,fun); This applies fun to each subset of elements in val that have identical subscripts in subs . The documentation however states: If the subscripts in subs are not sorted with respect to their linear indices, fun should not depend on the order of the values in its input data. How can we implement a stable version of accumarray , which doesn\'t have this limitation, but will

Is python&#39;s sorted() function guaranteed to be stable?

╄→尐↘猪︶ㄣ 提交于 2019-11-26 02:20:22
问题 The documentation doesn\'t guarantee that. Is there any other place that it is documented? I\'m guessing it might be stable since the sort method on lists is guaranteed to be stable (Notes 9th point: \"Starting with Python 2.3, the sort() method is guaranteed to be stable\"), and sorted is functionally similar. However, I\'m not able to find any definitive source that says so. Purpose: I need to sort based on a primary key and also a secondary key in cases where the primary key is equal in

What is the stability of the Array.sort() method in different browsers?

。_饼干妹妹 提交于 2019-11-26 00:15:52
问题 I know that the ECMA Script specification does not specify which algorithm to use for sorting arrays, nor does it specify whether the sort should be stable. I\'ve found this information for Firefox which specifies that firefox uses a stable sort. Does anyone know about IE 6/7/8, Chrome and Safari? 回答1: As of ES2019, sort is required to be stable. In ECMAScript 1st edition through ES2018, it was allowed to be unstable. Simple test case (ignore the heading, second set of numbers should be