Re(2): easiest way to sort a list?

*To*: mathgroup at smc.vnet.net*Subject*: [mg18359] Re(2): easiest way to sort a list?*From*: Andrzej Kozlowski <andrzej at tuins.ac.jp>*Date*: Wed, 30 Jun 1999 14:13:26 -0400*Sender*: owner-wri-mathgroup at wolfram.com

Actually I am using version 3.01 on a Mac PowerBook G3 (233 mghz). This could be machine dependent. What platform did you use for your tests? (Wri still have not sent me my Mathematica version 4.0 so I can't check this myself.) Andrzej On Mon, Jun 28, 1999, Colin Rose <colin at tri.org.au> wrote: > UnsortedUnion[lis_]:= > Part[lis, Sort[Map[Position[lis, #][[1]] &, Union[lis]] // Flatten]] > > OrderedUnion[li_]:=Block[{i}, > i[n_]:=(i[n]=Sequence[];n); > i /@ li] > > > >Andrzej Kozlowski wrote: > >> Although in your example UnsortedUnion comes just ahead of OrderedUnion, >> at the other extreme we get: > > > list1=Range[1000]; > > > OrderedUnion[list1];//Timing > > {0.15 Second, Null} > > > UnsortedUnion[list1];//Timing > > {1.91667 Second, Null} > > >Actually, in v4, for this example, UnsortedUnion is still >faster than OrderedUnion: > > >In[4]:= OrderedUnion[list1]; // Timing >Out[4]= {0.116667 Second, Null} > >In[5]:= UnsortedUnion[list1]; // Timing >Out[5]= {0.0666667 Second, Null} > > >Perhaps you are using an old version of Mathematica, in which >Sort is much slower. Of course, the essence of your point is >correct. That is, there are two types of large problems: > >* When the number of distinct elements is large: > - here OrderedUnion is MUCH faster. > >* When the list is large, but the number of distinct elements is small. > - here OrderedUnion is not faster. > >As an aside, in both cases, OrderedUnion may have memory problems. >For instance, a list of length 500000 will 'quit' most people's kernels. > > >Cheers > >Colin > >Colin Rose >tr(I) - Theoretical Research Institute >__________________________________________ >colin at tri.org.au http://www.tri.org.au/ > > > > > > > > Andrzej Kozlowski Toyama International University JAPAN http://sigma.tuins.ac.jp/ http://eri2.tuins.ac.jp/