Let the array be X and let n = length (X). Put each element x in the bucket number gender ((x - min (X)) * (n - 1) / (max (X) - min (X))). The width of each bucket is (max (X) - min (X)) / (n - 1), and the maximum adjacent difference is at least the same, so the numbers in question end up in different buckets. Now all we need to do is consider the pairs in which one is maximum in bucket i and the other is min in bucket j, where i <j and all buckets k in (i, j) are empty. This is linear time.
Proof that we really need a word: let f (X) be a function. If we could calculate f (X) in linear time, then of course we could solve in linear time that
0 <f (X)? (max (X) - min (X)) / (length (X) - 1),
i, that is, whether the elements of X are uniformly distributed and not all are the same. Let this predicate be P (X). P support has factorial (length (X)) components, so regular and Omega are used; (n log n) lower bounds for algebraic computation models.
zxc
source share