Skip to content

9. Partial, Online, and Adaptive Sorting

Sorting under constraints: partial sort, online insertion, adaptive merge, Timsort internals, and lazy or order-maintenance sorting.

indexslugname
256partial-sortPartial Sort
257top-k-sortTop K Sort
258incremental-sortIncremental Sort
259online-insertion-sortOnline Insertion Sort
260adaptive-merge-sortAdaptive Merge Sort
261natural-runs-sortNatural Runs Sort
262patience-sorting-lisPatience Sorting for LIS
263replacement-selectionReplacement Selection
264nearly-sorted-insertion-sortNearly Sorted Insertion Sort
265k-sorted-array-sortK Sorted Array Sort
266min-heap-k-sorted-sortMin Heap K Sorted Sort
267timsort-run-detectionTimsort Run Detection
268galloping-mergeGalloping Merge
269adaptive-samplesortAdaptive Samplesort
270adaptive-shivers-sortAdaptive Shivers Sort
271patience-sort-with-pilesPatience Sort with Piles
272online-topological-sortOnline Topological Sort
273insertion-sort-with-sentinelInsertion Sort with Sentinel
274binary-tree-online-sortBinary Tree Online Sort
275stream-sort-by-bufferStream Sort by Buffer
276sliding-window-sortSliding Window Sort
277rolling-median-sortRolling Median Sort
278external-replacement-selectionExternal Replacement Selection
279adaptive-heap-sortAdaptive Heap Sort
280smoothsort-adaptive-heap-sortSmoothsort Adaptive Heap Sort
281cartesian-tree-adaptive-sortCartesian Tree Adaptive Sort
282tournament-tree-partial-sortTournament Tree Partial Sort
283lazy-sortLazy Sort
284lazy-selection-sortLazy Selection Sort
285order-maintenance-sortOrder Maintenance Sort
Partial SortRearrange a sequence so that the smallest k elements appear in sorted order, without fully sorting the entire sequence.
2 min
Top K SortExtract and sort the top k elements (smallest or largest) from a sequence without fully sorting it.
2 min
Incremental SortMaintain a sorted sequence while elements are inserted one by one, updating order incrementally.
2 min
Online Insertion SortSort a sequence as elements arrive by inserting each new item into its correct position among the items already seen.
2 min
Adaptive Merge SortA merge sort variant that exploits existing order in the input by detecting natural runs and reducing work.
2 min
Natural Runs SortSort a sequence by detecting already sorted runs and repeatedly merging them.
2 min
Patience Sorting (LIS)Use patience sorting to compute the length and structure of the longest increasing subsequence efficiently.
2 min
Replacement SelectionGenerate long sorted runs from a stream using a heap, commonly used in external sorting.
2 min
Nearly Sorted Insertion SortSort an almost ordered sequence efficiently by using insertion sort, whose running time improves when few elements are far from their final positions.
3 min
K Sorted Array SortSort an array where every element is at most k positions away from its final sorted position.
2 min
Min Heap K Sorted SortSort a k-sorted array using a sliding min heap window of size k+1.
2 min
Timsort Run DetectionDetect natural runs in input and normalize them for efficient merging in Timsort.
2 min
Galloping MergeAccelerate merging by switching from one-by-one comparison to exponential search when one run wins repeatedly.
3 min
Adaptive SamplesortPartition data by sampled splitters, while adapting splitter choice to skewed or partially ordered input.
3 min
Adaptive Shivers SortAn adaptive merge-based sorting algorithm that merges natural runs using stack rules designed to minimize merge cost.
2 min
Patience Sort with PilesSort a sequence by building piles using patience sorting and then merging them.
2 min
Online Topological SortMaintain a valid topological ordering of a directed acyclic graph as vertices or edges are added over time.
3 min
Insertion Sort with SentinelOptimize insertion sort by placing the minimum element at the front so the inner loop does not need a bounds check.
2 min
Binary Tree Online SortMaintain a sorted sequence by inserting elements into a binary search tree as they arrive and extracting them in order.
2 min
Stream Sort by BufferSort a stream in bounded chunks by buffering records, sorting each chunk, and emitting sorted runs or partially ordered output.
2 min
Sliding Window SortMaintain sorted order over a moving window of the most recent elements in a stream.
2 min
Rolling Median SortMaintain the median of a sliding window using two heaps while the window moves over a stream.
2 min
External Replacement SelectionGenerate long initial runs for external sorting using replacement selection with disk-based streams.
2 min
Adaptive Heap SortA heap-based sorting method that adapts to partially ordered input to reduce unnecessary heap operations.
2 min
Smoothsort Adaptive Heap SortSort in place with a heap-like structure that keeps worst-case O(n log n) time while approaching linear time on nearly sorted input.
2 min
Cartesian Tree Adaptive SortSort by building a Cartesian tree that captures local order, then extracting elements in sorted order.
2 min
Tournament Tree Partial SortUse a tournament tree to extract the smallest or largest k elements in sorted order without fully sorting the input.
2 min
Lazy SortDelay sorting work until ordered output or ordered queries are actually needed.
2 min
Lazy Selection SortSelect the next smallest element on demand, avoiding full sorting until all elements are requested.
2 min
Order Maintenance SortMaintain a dynamically ordered sequence under insertions and comparisons without fully re-sorting.
2 min