ArrayV
ArrayV copied to clipboard
New Sort:Hyper Stooge Sort
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)
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);
}
}