octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stable sorts


From: Ed Meyer
Subject: Re: stable sorts
Date: Sat, 25 Aug 2012 18:55:58 -0700



On Sat, Aug 25, 2012 at 3:44 PM, Ben Abbott <address@hidden> wrote:
On Aug 25, 2012, at 6:18 PM, Michael D Godfrey wrote:

> On 08/25/2012 05:55 PM, Ben Abbott wrote:
>
>> ok. Thanks.  The sort() in Matlab 2011b is stable.
>> i =
>>
>>      4
>>      1
>>      2
>>      3
>>      5
>
> Ben,
> I read this as NOT stable, just like Octave.
> Stable would give: 4 1 3 2 5
>
> Something wrong?
> Michael

I assume wiki has the correct definition?

"Stable sorting algorithms maintain the relative order of records with equal keys."
http://en.wikipedia.org/wiki/Sorting_algorithm#Stability

Since since x(2) and x(3) == 2, it looks to me as if Matlab's result is stable (relative order is maintained).

Ben

Just because it has kept the order of x(2) and x(3) does not necessarily mean it is a stable sort;
an unstable sort can do either but a stable sort is guaranteed to keep the original order.

--
Ed Meyer


reply via email to

[Prev in Thread] Current Thread [Next in Thread]