MathGroup Archive 2005

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

Search the Archive

Re: Finding Position in an ordered list


Hi Janos,

Here is a little experiment.

First I create a list of strings.

$Version
5.1 for Microsoft Windows (January 27, 2005)

Needs["Miscellaneous`Dictionary`"]

words = FindWords[__];

Length[words]
92836

Now I search the position of four words with Position:

Timing[
  {Position[words,"egg"],Position[words,"book
      "],Position[words,"you"],Position[words,"paper"]}]
{0.05 Second, {{{25730}}, {{8885}}, {{92516}}, {{57800}}}}

Now I create a little database: 

db = Dispatch[Thread[words -> Range[Length[words]]]];

Timing[{"egg", "book", "you", "paper"} /. db]
{0. Second,{25730,8885,92516,57800}}

It is faster, as wanted. 

Janos, maybe you could now determine the search time as a function of
the list size.

Cheers, Vittorio


>-----Original Message-----
>From: janostothmeister at gmail.com [mailto:janostothmeister at gmail.com]
To: mathgroup at smc.vnet.net
>Sent: Monday, June 06, 2005 10:21 AM
>Subject: [mg57738] [mg57720] Finding Position in an ordered list
>
>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: Quadratic Form Contours
  • Next by Date: Re: refering to a long pattern by a variable
  • Previous by thread: Re: Finding Position in an ordered list
  • Next by thread: Re: Finding Position in an ordered list