Skip to main content
Log in

Analysis of an adaptive algorithm to find the two nearest neighbors

  • Published:
Algorithmica Aims and scope Submit manuscript

Abstract

Given a setS ofN distinct elements in random order and a pivotxS, 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.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Similar content being viewed by others

References

  1. L. Comtet.Advanced Combinatorics. Reidel, Dordrecht, 1974.

    MATH  Google Scholar 

  2. 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.

    Google Scholar 

  3. P. Flajolet, P.V. Poblete, and A. Viola. On the analysis of linear probing hashing.Algorithmica, 22(4):490–515, December 1998.

    Article  MATH  MathSciNet  Google Scholar 

  4. G.H. Gonnet and R. Baeza-Yates.Handbook of Algorithms and Data Structures, second edition. Addison-Wesley, Reading, MA, 1991.

    Google Scholar 

  5. 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.

    Article  MATH  MathSciNet  Google Scholar 

  6. R.L. Graham, D.E. Knuth, and O. Patashnik.Concrete Mathematics. Addison-Wesley, Reading, MA, 1989.

    MATH  Google Scholar 

  7. P.V. Poblete. Approximating functions by their Poisson transform.Information Processing Letters, 23:127–130, 1986.

    Article  MATH  MathSciNet  Google Scholar 

  8. 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.

    Article  MATH  MathSciNet  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

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

Reprints 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

Download citation

  • Received:

  • Revised:

  • Issue Date:

  • DOI: https://doi.org/10.1007/BF02679620

Key Words

Navigation