8 ms·
But they're not identical, they differ by a comma. It's a desired feature of sorting algorithms that they should be deterministic, in which case arbitrarily or
by crazygringo 5y ago
But they're not identical, they differ by a comma.
It's a desired feature of sorting algorithms that they should be deterministic, in which case arbitrarily ordered input should produce identical output.
Otherwise, having non-deterministic output just makes everything harder -- harder to make comparisons, more work to write tests, etc.
- thaumasiotes 5y ago> But they're not identical, they differ by a comma. This makes as much sense as saying that "Stop me!" and "Stop me!" aren't identical, because one of them is first and the other is second. It's true, but it's not relevant to sorting them. Your "desired feature of sorting algorithms" is most commonly realized as the question of whether the algorithm provides a "stable" sort -- that is, whether two values that compare equal are guaranteed to occur in the same order in the (sorted) output that they did in the (unsorted) input. There are applications where this is considered desirable, and many other applications where it isn't. But there are no applications in which it's not possible for two values to compare equal. For the question of stable sorting to arise in the first place, you have to have already realized that you're going to be sorting things that compare equal.
- crazygringo 5y ago...which is why it's generally desirable for unequal things to never compare equal. Stability is about preserving the order of items that compare equally. That's a different topic. I'm talking about it being desirable not to underspecify the comparison function (sorting rules), so that unequal items are never compared as equal.