Checking sorted-order invariants cheaply
Beginner
Asymptotics & empirical timing
Created by Pavel
· 29.04.2026 at 19:08 UTC
Monotonicity checks appear in time-series QA (“is this slice non-decreasing?”), in merge routines that assume sorted runs, and in validating that a quantile transform was applied correctly. A single left-to-right pass comparing neighbours is Θ(n) and early-exits on the first violation—cheaper than sorting just to test order.
Do not confuse “check sorted” with “sort”: sorting costs Θ(n log n) comparison sorts; verifying sorted is linear.
For duplicate-tolerant definitions, be explicit: strict < vs <= changes validity of flat segments.
Sorting how-to (when you actually need sort): [1].
Sources
University approvals: 0
Tasks
Card Info
- Topic: Asymptotics & empirical timing
- Difficulty: Beginner
- Completed: 0 users
Creator
Pavel