Stooge Sort
Recursive sorting dividing into thirds. O(n^2.7). Educational curiosity.
Visualization
Interactive visualization for Stooge Sort
Interactive visualization with step-by-step execution
Implementation
1function stoogeSort(arr: number[], l = 0, r = arr.length - 1): number[] {
2 const a = l === 0 ? [...arr] : arr;
3 if (a[l] > a[r]) [a[l], a[r]] = [a[r], a[l]];
4 if (r - l + 1 > 2) {
5 const t = Math.floor((r - l + 1) / 3);
6 stoogeSort(a, l, r - t);
7 stoogeSort(a, l + t, r);
8 stoogeSort(a, l, r - t);
9 }
10 return a;
11}Deep Dive
Theoretical Foundation
Recursively sorts first 2/3, last 2/3, then first 2/3 again. Very inefficient but interesting recursive structure.
Complexity
Time
O(n^2.7)
O(n^2.7)
O(n^2.7)
Space
O(n)
Applications
Industry Use
Educational: recursion patterns
Use Cases
Related Algorithms
Quicksort
A highly efficient, in-place sorting algorithm that uses divide-and-conquer strategy. Invented by Tony Hoare in 1959, it remains one of the most widely used sorting algorithms due to its excellent average-case performance and cache efficiency.
Merge Sort
A stable, divide-and-conquer sorting algorithm with guaranteed O(n log n) performance.
Bubble Sort
Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping adjacent elements if they are in the wrong order. This process is repeated until the entire array is sorted. Named for the way larger elements 'bubble' to the top (end) of the array.
Insertion Sort
Insertion Sort is a simple, intuitive sorting algorithm that builds the final sorted array one element at a time. It works similarly to how people sort playing cards in their hands - picking each card and inserting it into its correct position among the already sorted cards. Despite its O(n²) time complexity, Insertion Sort is efficient for small datasets and nearly sorted arrays, making it practical for real-world applications.