Abstract
Given a setS ofN distinct elements in random order and a pivotx ∈S, we study the problem of simultaneously finding the left and the right neighbors ofx, i.e.,L=max{u|u<x} andR=min{v|v>x}.
We analyze an adaptive algorithm that solves this problem by scanning the setS while maintaining current values for the neighborsL andR. Each new element inspected is compared first against the neighbor in the most populous side, then (if necessary) against the neighbor in the other side, and finally (if necessary), against the pivot.
This algorithm may require 3N comparisons in the worst case, but it performs well on the average. If the pivot has rankαN, where α is fixed and <1/2, the algorithm does (1+α)N+Θ(logN) comparisons on the average, with a variance of 3 lnN+Θ(1). However, in the case where the pivot is the median, the average becomes 3/2;N+Θ(√N), while the variance grows to (1/2−π/8)N+Θ(logN).
We also prove that, in the αN case, the limit distribution is Gaussian.
Similar content being viewed by others
References
L. Comtet.Advanced Combinatorics. Reidel, Dordrecht, 1974.
W. Cunto, J.I. Munro, and P.V. Poblete. A case study in comparison based complexity finding the nearest value(s). InProceedings of the 2nd Workshop on Algorithms and Data Structures — WADS 91, Ottawa, pages 1–12. Springer-Verlag, New York, August 1991.
P. Flajolet, P.V. Poblete, and A. Viola. On the analysis of linear probing hashing.Algorithmica, 22(4):490–515, December 1998.
G.H. Gonnet and R. Baeza-Yates.Handbook of Algorithms and Data Structures, second edition. Addison-Wesley, Reading, MA, 1991.
G.H. Gonnet and J.I. Munro. The analysis of linear probing sort by the use of a new mathematical transform.Journal of Algorithms, 5:451–470, 1984.
R.L. Graham, D.E. Knuth, and O. Patashnik.Concrete Mathematics. Addison-Wesley, Reading, MA, 1989.
P.V. Poblete. Approximating functions by their Poisson transform.Information Processing Letters, 23:127–130, 1986.
P.V. Poblete, A. Viola, and J.I. Munro. The diagonal Poisson transform and its applications to the analysis of a hashing scheme.Random Structures & Algorithms, 10:221–255, 1997.
Author information
Authors and Affiliations
Additional information
Communicated by H. Prodinger and W. Szpankowski.
This work has been supported in part by Grant FONDECYT(Chile) 1950622 and 1981029.
Online publication October 6, 2000.
Rights and permissions
About this article
Cite this article
Poblete, P.V. Analysis of an adaptive algorithm to find the two nearest neighbors. Algorithmica 29, 227–237 (2001). https://doi.org/10.1007/BF02679620
Received:
Revised:
Issue Date:
DOI: https://doi.org/10.1007/BF02679620