Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

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: [mg114162] Re: Efficient search for bounding list elements
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Thu, 25 Nov 2010 07:04:26 -0500 (EST)
  • References: <iclfhg$lgi$1@smc.vnet.net>

On Nov 25, 2:58 am, David Skulsky <edskul... at gmail.com> 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

See "Finding Position in an ordered list", June 6-9, 2005,
http://groups.google.ca/group/comp.soft-sys.math.mathematica/browse_frm/thread/89b039517acde967


  • Prev by Date: How to add a LegendLabel to a Chartlegends in BarChart
  • Next by Date: Re: Efficient search for bounding list elements
  • Previous by thread: Re: Efficient search for bounding list elements
  • Next by thread: Re: Efficient search for bounding list elements