Re: Finding Position in an ordered list
- To: mathgroup at smc.vnet.net
- Subject: [mg57738] Re: [mg57720] Finding Position in an ordered list
- From: "Caffa Vittorio Dr." <Caffa at iabg.de>
- Date: Tue, 7 Jun 2005 02:03:38 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
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
>