Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stability #1

Open
scandum opened this issue Dec 7, 2021 · 1 comment
Open

Stability #1

scandum opened this issue Dec 7, 2021 · 1 comment

Comments

@scandum
Copy link

scandum commented Dec 7, 2021

I took a quick look at your code, which looks great btw, and noticed the sort might not be stable.

// array[0] and array[2]
// array[1] and array[3]
// array[0] and array[1]
// array[2] and array[3]
// array[1] and array[2]

If you change this to:

// array[0] and array[1]
// array[2] and array[3]
// array[1] and array[2]
// array[0] and array[1]
// array[2] and array[3]
// array[1] and array[2]

it should be stable, since you'll always be comparing adjacent elements. It's possible to do it with 5 comparisons, but you'll need a pretty complex decision tree to keep it stable.

@ameekkhan
Copy link
Owner

ameekkhan commented Jul 8, 2022

I am very glad that you like my sort. I am very thankful for your correction to this algorithm now it will be stable. And I will test it and also compare it with all other sorts its execution times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants