We present a new sorting algorithm that adapts to existing order withi
n an input sequence. Let k be the smallest integer such that a sequenc
e X of length n can be reduced to the empty sequence by the removal of
k monotone, increasing or decreasing subsequences. The algorithm, Sla
bsort, Sorts X in 0(n log k) time, without knowing k beforehand, which
is optimal in a comparison-based model. (C) 1994 Academic Press, Inc.