Slow Sort
Slow Sort :
Author(s) : Andrei Broder and Jorge Stolfi Date : 1986Slowsort is a humorous sorting algorithm. It is based on the principle of multiply and surrender, a tongue-in-cheek joke of divide and conquer. It was published in 1986 by Andrei Broder and Jorge Stolfi in their paper Pessimal Algorithms and Simplexity Analysis. This algorithm is of multiply and surrender type; the problem is divided into subproblems, but the subproblems are not solved independently.
| Time Complexity | O(n^(log n)) |
| Best Case | O(n^(log n)) |
| Worst Case | O(n^(log n)) |
| Space Complexity | O(n) |
| Stable | No |
Code Integration:
* the code might contain some bugs or may not work correctly
def slow_sort(arr, i, j):
if i >= j:
return
m = (i + j) // 2
slow_sort(arr, i, m)
slow_sort(arr, m + 1, j)
if arr[j] < arr[m]:
arr[j], arr[m] = arr[m], arr[j]
slow_sort(arr, i, j - 1)
function slowSort(arr, i, j) {
if (i >= j) return;
let m = Math.floor((i + j) / 2);
slowSort(arr, i, m);
slowSort(arr, m + 1, j);
if (arr[j] < arr[m]) {
[arr[j], arr[m]] = [arr[m], arr[j]];
}
slowSort(arr, i, j - 1);
}
public static void slowSort(int[] arr, int i, int j) {
if (i >= j) return;
int m = (i + j) / 2;
slowSort(arr, i, m);
slowSort(arr, m + 1, j);
if (arr[j] < arr[m]) {
int temp = arr[j];
arr[j] = arr[m];
arr[m] = temp;
}
slowSort(arr, i, j - 1);
}
func slowSort(arr []int, i, j int) {
if i >= j {
return
}
m := (i + j) / 2
slowSort(arr, i, m)
slowSort(arr, m+1, j)
if arr[j] < arr[m] {
arr[j], arr[m] = arr[m], arr[j]
}
slowSort(arr, i, j-1)
}
void slowSort(int arr[], int i, int j) {
if (i >= j) return;
int m = (i + j) / 2;
slowSort(arr, i, m);
slowSort(arr, m + 1, j);
if (arr[j] < arr[m]) {
int temp = arr[j];
arr[j] = arr[m];
arr[m] = temp;
}
slowSort(arr, i, j - 1);
}