Skip to content

6. Elementary Sorting

Elementary comparison-based sorts: bubble, selection, insertion, Shell, comb, cycle, and curiosity sorts.

indexslugname
151bubble-sortBubble Sort
152optimized-bubble-sortOptimized Bubble Sort
153cocktail-shaker-sortCocktail Shaker Sort
154odd-even-sortOdd Even Sort
155gnome-sortGnome Sort
156selection-sortSelection Sort
157stable-selection-sortStable Selection Sort
158double-selection-sortDouble Selection Sort
159insertion-sortInsertion Sort
160binary-insertion-sortBinary Insertion Sort
161shell-sortShell Sort
162shell-sort-shell-gapsShell Sort with Shell Gaps
163shell-sort-hibbard-gapsShell Sort with Hibbard Gaps
164shell-sort-sedgewick-gapsShell Sort with Sedgewick Gaps
165comb-sortComb Sort
166cycle-sortCycle Sort
167pancake-sortPancake Sort
168stooge-sortStooge Sort
169slow-sortSlow Sort
170bead-sortBead Sort
171strand-sortStrand Sort
172library-sortLibrary Sort
173patience-sortPatience Sort
174tree-sortTree Sort
175tournament-sortTournament Sort
176smoothsortSmoothsort
177weak-heap-sortWeak Heap Sort
178cartesian-tree-sortCartesian Tree Sort
179bingo-sortBingo Sort
180exchange-sortExchange Sort
Optimized Bubble SortBubble sort with early termination when no swaps occur, reducing unnecessary passes on nearly sorted data.
2 min
Cocktail Shaker SortA bidirectional variant of bubble sort that alternates passes from left to right and right to left.
3 min
Odd Even SortA variation of bubble sort that alternates between comparing odd-even and even-odd index pairs.
3 min
Gnome SortA simple sorting algorithm that moves elements backward when out of order, similar to insertion sort with swaps.
2 min
Selection SortRepeatedly select the minimum element from the unsorted portion and place it at the beginning.
2 min
Stable Selection SortA stable variant of selection sort that preserves the relative order of equal elements by shifting instead of swapping.
2 min
Double Selection SortSelect both minimum and maximum elements in each pass and place them at the beginning and end.
3 min
Insertion SortBuild a sorted sequence by inserting each element into its correct position.
2 min
Binary Insertion SortInsertion sort that uses binary search to find the insertion position, reducing comparisons.
3 min
Shell SortGeneralization of insertion sort that compares elements at a gap, reducing long-distance inversions early.
2 min
Shell Sort with Shell GapsShell sort using the original gap sequence n/2, n/4, ..., 1.
3 min
Shell Sort with Hibbard GapsShell sort using Hibbard gap sequence 1, 3, 7, 15, ..., improving over simple halving.
3 min
Shell Sort with Sedgewick GapsShell sort using Sedgewick gap sequence for improved practical performance.
3 min
Comb SortA bubble-sort variant that compares elements at a shrinking gap to remove long-distance inversions early.
3 min
Cycle SortMinimizes writes by placing each element directly into its correct position using cycles.
3 min
Pancake SortSort by repeatedly flipping prefixes to move the maximum element to its correct position.
2 min
Stooge SortA recursive sorting algorithm with extremely poor performance based on overlapping subproblems.
2 min
Slow SortA deliberately inefficient recursive sorting algorithm based on divide and conquer followed by maximum placement.
3 min
Bead SortSort non-negative integers by simulating gravity on beads arranged in columns.
3 min
Strand SortExtract increasing subsequences and merge them to form a sorted sequence.
3 min
Library SortAn insertion-based sorting algorithm that leaves gaps between elements to reduce shifting.
3 min
Patience SortSort by building piles using patience card game rules and then merging them.
3 min
Tree SortInsert all elements into a binary search tree, then traverse the tree in sorted order.
3 min
Tournament SortSort by repeatedly selecting the minimum element using a tournament tree.
3 min
SmoothsortAn adaptive in-place comparison sort based on Leonardo heaps.
3 min
Weak Heap SortA variant of heapsort using weak heaps with fewer comparisons.
4 min
Cartesian Tree SortSort by building a Cartesian tree and extracting elements via inorder traversal.
3 min
Bingo SortRepeatedly place all occurrences of the current minimum value before moving to the next distinct value.
3 min
Exchange SortA simple quadratic sorting algorithm that compares all pairs and swaps out-of-order elements.
2 min
Bubble SortRepeatedly swap adjacent elements that are out of order until the sequence becomes sorted.
2 min