stooge sort time complexity on2 709 reference https www geeksforgeeks orgstoogesort if first element is smaller than last swap them if there are more than 2 elements in the array recursively sort first 2 3 elements recursively sort last 2 3 elements recursively sort first 2 3 elements again to confirm if first element is smaller than last swap them if there are more than 2 elements in the array recursively sort first 2 3 elements recursively sort last 2 3 elements recursively sort first 2 3 elements again to confirm
def stoogesort(arr, l, h): 
    if l >= h: 
        return
   
    
    
    if arr[l]>arr[h]: 
        t = arr[l] 
        arr[l] = arr[h] 
        arr[h] = t 
   
    
    
    if h-l + 1 > 2: 
        t = (int)((h-l + 1)/3) 
   
        
        stoogesort(arr, l, (h-t)) 
   
        
        stoogesort(arr, l + t, (h)) 
   
        
        
        stoogesort(arr, l, (h-t)) 
        

if __name__ == "__main__":
    array = [1,3,64,5,7,8]
    n = len(array) 
    stoogesort(array, 0, n-1) 
    for i in range(0, n): 
        print(array[i], end = ' ')