Stooge sort
Encyclopedia
Stooge sort is a recursive
Recursion
Recursion is the process of repeating items in a self-similar way. For instance, when the surfaces of two mirrors are exactly parallel with each other the nested images that occur are a form of infinite recursion. The term has a variety of meanings specific to a variety of disciplines ranging from...

 sorting algorithm
Sorting algorithm
In computer science, a sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order...

 with a time complexity of ).
The running time of the algorithm is thus extremely slow compared
to efficient sorting algorithms, such as Merge sort
Merge sort
Merge sort is an O comparison-based sorting algorithm. Most implementations produce a stable sort, meaning that the implementation preserves the input order of equal elements in the sorted output. It is a divide and conquer algorithm...

, and is even slower than Bubble sort
Bubble sort
Bubble sort, also known as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which...

, a canonical example of a fairly inefficient and simple sort.

The algorithm is defined as follows:
  • If the value at the end is smaller than the value at the start, swap them.
  • If there are three or more elements in the current list subset, then:
    • Stooge sort the initial 2/3 of the list
    • Stooge sort the final 2/3 of the list
    • Stooge sort the initial 2/3 of the list again
  • else: exit the procedure


The algorithm gets its name from slapstick
Slapstick
Slapstick is a type of comedy involving exaggerated violence and activities which may exceed the boundaries of common sense.- Origins :The phrase comes from the batacchio or bataccio — called the 'slap stick' in English — a club-like object composed of two wooden slats used in Commedia dell'arte...

 routines of the Three Stooges
Three Stooges
The Three Stooges were an American vaudeville and comedy act of the early to mid–20th century best known for their numerous short subject films. Their hallmark was physical farce and extreme slapstick. In films, the Stooges were commonly known by their first names: "Moe, Larry, and Curly" and "Moe,...

, in which each stooge hits the other two.

Implementation


algorithm stoogesort(array L, i = 0, j = length(L)-1)
if L[j] < L[i] then
L[i] ↔ L[j]
if (j - i + 1) >= 3 then
t = (j - i + 1) / 3
stoogesort(L, i , j-t)
stoogesort(L, i+t, j )
stoogesort(L, i , j-t)
return L

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK