Created
December 30, 2020 20:33
-
-
Save nathanielbd/d443ad1ea11abd14a47bfcfebed6c25c to your computer and use it in GitHub Desktop.
A reluctant sorting algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.mipmip.org/tidbits/pasa.pdf | |
# Pessimal Algorithmsand Simplexity Analysis. Broder, Stolfi | |
def helper(A, i, j): | |
# in-place sort the subarray A[i],...,A[j] using multiply-and-surrender | |
if i >= j: | |
return | |
m = (i+j)//2 | |
helper(A, i, m) | |
helper(A, m+1, j) | |
if A[m] > A[j]: | |
A[m],A[j] = A[j],A[m] | |
helper(A, i, j-1) | |
# start recursion and return the sorted array | |
def slowsort(A): | |
helper(A, 0, len(A)-1) | |
return A |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment