Strand Sort
Extract increasing strands from input and merge them into the result until input is empty.
Visualization
Interactive visualization for Strand Sort
Strand Sort Visualization
Interactive visualization with step-by-step execution
Implementation
1function strandSort(arr: number[]): number[] {
2 let input = [...arr];
3 let result: number[] = [];
4 const merge = (a: number[], b: number[]) => {
5 const out: number[] = [];
6 let i = 0, j = 0;
7 while (i < a.length && j < b.length) out.push(a[i] <= b[j] ? a[i++] : b[j++]);
8 while (i < a.length) out.push(a[i++]);
9 while (j < b.length) out.push(b[j++]);
10 return out;
11 };
12 while (input.length) {
13 const strand: number[] = [input.shift()!];
14 for (let i = 0; i < input.length;) {
15 if (input[i] >= strand[strand.length - 1]) { strand.push(input[i]); input.splice(i, 1); }
16 else i++;
17 }
18 result = merge(result, strand);
19 }
20 return result;
21}Deep Dive
Theoretical Foundation
Repeatedly form an increasing subsequence (strand) by scanning input and moving elements ≥ last of the strand, then stable-merge the strand into the result.
Complexity
Time
O(n log n) (with long runs)
O(n²)
O(n²)
Space
O(n)
Applications
Industry Use
Educational
Small inputs with natural runs
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.