---
title: Adaptive sort
slug: adaptive-sort
qid: 
snapshot: enwiki-001376833342
content_hash: 
license: CC BY-SA 4.0
source: https://en.wikipedia.org/w/index.php?oldid=1376833342
tags: [23118434, 23603337, 27152323]
---

# Adaptive sort

> [!note] Provenance
> Snapshot `enwiki-001376833342` · content root `…`
> Derived from <https://en.wikipedia.org/w/index.php?oldid=1376833342> · Licensed CC BY-SA 4.0

A sorting algorithm falls into the adaptive sort family if it takes advantage of existing order in its input. It benefits from the presortedness in the input sequence – or a limited amount of disorder for various definitions of measures of disorder – and sorts faster. Adaptive sorting is usually performed by modifying existing sorting algorithms.

A sorting algorithm falls into the adaptive sort family if it takes advantage of existing order in its input. It benefits from the presortedness in the input sequence – or a limited amount of disorder for various definitions of measures of disorder – and sorts faster. Adaptive sorting is usually performed by modifying existing sorting algorithms. for j = 1 to length(X) - 1 do t ← X[j] i ← j while i > 0 and X[i - 1] > t do X[i] ← X[i - 1] i ← i - 1 end X[i] ← t end The performance of this algorithm can be described in terms of the number of inversions in the input, and then will be roughly equal to , where is the number of inversions. Using this measure of presortedness – being relative to the number of inversions – insertion sort takes less time to sort the closer the array of data is to being sorted. Other examples of adaptive sorting algorithms are adaptive heap sort, adaptive merge sort, patience sort, Shellsort, smoothsort, splaysort, Timsort, and Cartesian tree sorting.
