MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Efficient search for bounding list elements

  • To: mathgroup at
  • Subject: [mg114154] Efficient search for bounding list elements
  • From: David Skulsky <edskulsky at>
  • Date: Thu, 25 Nov 2010 05:58:49 -0500 (EST)

I've been looking for a way to efficiently find the indices of the two
elements of a monotonically increasing list which bound a number.  For
example, if

a = Range[1000,5000,250]



then I'd like this function (e.g., searchFunction[x,a]) to return
{3,4}, which correspond to the 3rd and 4th elements of a, which are
1500 and 1750, respectively.

I can easily do this in a loop, but in my application a can be very
large (hundreds of thousands or millions of elements) and this
operation needs to repeated thousands of times, so efficiency is

Any suggestions would be greatly appreciated!


David Skulsky

  • Prev by Date: Re: Resolution of CurrentImage[]?
  • Next by Date: Re: Why this can't be reduced by mathematica?!
  • Previous by thread: Re: understanding code
  • Next by thread: Re: Efficient search for bounding list elements