MathGroup Archive 2005

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

Search the Archive

Re: Finding Position in an ordered list


Hi Janos,
I think "DiscreteMath`Combinatorica`BinarySearch" is what you are 
searching for.

?BinarySearch

BinarySearch[l, k] searches sorted list l for key k and gives the 
position of l containing k, if k is present in l. Otherwise, if k is 
absent in l, the function returns (p + 1/2) where k falls between the 
elements of l in positions p and p+1. BinarySearch[l, k, f] gives the 
position of k in the list obtained from l by applying f to each element 
in l.

sincerely, Daniel

janostothmeister at gmail.com wrote:
> I wonder if it is possible to use the knowledge
> that a list in which I am looking for the position
> of an element is ordered. I want a quicker solution then e.g.
> lis={ac,dmk,rfg,sty,zxxer}
> Position[lis,sty]
> 
> I am certainly interested in longer lists...
> 
> Thank you,
> 
> Janos
> 
> 


  • Prev by Date: Re: Finding Position in an ordered list
  • Next by Date: Re: Quadratic Form Contours
  • Previous by thread: Re: Finding Position in an ordered list
  • Next by thread: Re: Finding Position in an ordered list