MathGroup Archive 2010

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

Search the Archive

Re: Efficient search for bounding list elements

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114160] Re: Efficient search for bounding list elements
  • From: Oliver Ruebenkoenig <ruebenko at wolfram.com>
  • Date: Thu, 25 Nov 2010 07:04:04 -0500 (EST)
  • References: <201011251058.FAA21975@smc.vnet.net>

David,

On Thu, 25 Nov 2010, David Skulsky wrote:

> 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]
>
> and
>
> x=1600
>
> 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
> critical.
>
> Any suggestions would be greatly appreciated!
>
> Thanks,
>
> David Skulsky
>
>

perhaps this is useful

a = Range[1000, 5000, 250];
nf = Nearest[a]

nf[1600, 2]

hth,
Oliver


  • Prev by Date: Re: Efficient search for bounding list elements
  • Next by Date: Re: FindMaximum - f is a MathLink function
  • Previous by thread: Efficient search for bounding list elements
  • Next by thread: Re: Efficient search for bounding list elements