Efficient search for bounding list elements
- To: mathgroup at smc.vnet.net
- Subject: [mg114154] Efficient search for bounding list elements
- From: David Skulsky <edskulsky at gmail.com>
- 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] 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
- Follow-Ups:
- Re: Efficient search for bounding list elements
- From: Oliver Ruebenkoenig <ruebenko@wolfram.com>
- Re: Efficient search for bounding list elements