Stooge sort compares the endpoints of a range and swaps them if inverted. For a range longer than two elements, it recursively sorts the first two-thirds, the last two-thirds, then the first two-thirds again. The overlap repairs values displaced by the middle call.

Its three overlapping calls expand even when the range is already ordered. The algorithm is unstable because endpoint swaps are non-adjacent and is useful mainly as a recurrence-analysis exercise.

Visualization

The trace marks the active recursive range before comparing its endpoints. The visualization accepts at most seven items and stops at a 900-frame ceiling, preventing the three-way recursion from overwhelming either host.

Complexity
n
number of elements in the array
Sort
  • Best: Θ(n^log₁.₅3) ≈ Θ(n².7095)
  • Average: Θ(n^log₁.₅3) ≈ Θ(n².7095)
  • Worst: Θ(n^log₁.₅3) ≈ Θ(n².7095)

The recurrence is T(n) = 3T(2n/3) + O(1), giving Θ(n^log₁.₅3) ≈ Θ(n².7095). The recursion stack follows one branch at a time.

Boundary and implementation

Each child range is about two-thirds of its parent, but every non-base call branches three times. Already sorted input still expands the same call tree. The StepTrace ceiling bounds the demonstration only; it does not change the algorithm.

Questions

References