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

BogoStalinSort #168

Open
programminghoch10 opened this issue Sep 15, 2021 · 1 comment
Open

BogoStalinSort #168

programminghoch10 opened this issue Sep 15, 2021 · 1 comment

Comments

@programminghoch10
Copy link

programminghoch10 commented Sep 15, 2021

I propose addition of a new sorting algorithm which combines the best features of both stalinsort and bogosort.

The algorithm is fairly simple:
Just randomly remove elements until the array is in order.

Complexity ranges from O(n) to O(n²)

Hope this will make the world a better place!

@adri326
Copy link

adri326 commented Oct 12, 2021

Alternatively:

  1. Iterate through the array to verify that it is in order. If is is, exit the loop
  2. Pick two random indices i,j ∈ [0; n[; i < j
  3. If L[i] <= L[j], go back to step 2
  4. If L[i] > L[j], remove L[j]
  5. Go back to step 1

Best-case complexity is O(n), worst-case is O(n³) (n² random picks per iteration, n iterations, step 1 is dwarved by steps 2 and 3).

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