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

New Sort:Hyper Stooge Sort #116

Open
pystraf opened this issue Aug 23, 2024 · 1 comment
Open

New Sort:Hyper Stooge Sort #116

pystraf opened this issue Aug 23, 2024 · 1 comment

Comments

@pystraf
Copy link

pystraf commented Aug 23, 2024

The hyper stooge sorting is a sorting algorithm that worse than the stooge sorting.
Instead of recursing using two-thirds of the array, it is modified to n - 1.
It achieves a time complexity of O(3^n), It's very very bad!
So I set the unreasonable limit to 20.
(This algortihm is proposed by fungamer2)

@pystraf
Copy link
Author

pystraf commented Aug 23, 2024

An possible implementation:

package io.github.arrayv.sorts.exchange;

import io.github.arrayv.main.ArrayVisualizer;
import io.github.arrayv.sorts.templates.Sort;


public final class HyperStoogeSort extends Sort {
    public HyperStoogeSort(ArrayVisualizer arrayVisualizer) {
        super(arrayVisualizer);

        this.setSortListName("Hyper Stooge");
        this.setRunAllSortsName("Hyper Stooge Sort");
        this.setRunSortName("Hyper Stoogesort");
        this.setCategory("Impractical Sorts");
        this.setBucketSort(false);
        this.setRadixSort(false);
        this.setUnreasonablySlow(true);
        this.setUnreasonableLimit(20);
        this.setBogoSort(false);
    }

    private void hyperStoogeSort(int[] A, int i, int j) {
        if (Reads.compareIndices(A, i, j, 0.0025, true) == 1) {
            Writes.swap(A, i, j, 0.005, true, false);
        }

        if (j - i > 1) {
            this.hyperStoogeSort(A, i, j - 1);
            this.hyperStoogeSort(A, i + 1, j);
            this.hyperStoogeSort(A, i, j - 1);
        }
    }

    @Override
    public void runSort(int[] array, int currentLength, int bucketCount) {
        this.hyperStoogeSort(array, 0, currentLength - 1);
    }
}

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

1 participant