Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

RE: Re: Friendly Challenge 2: sort by column

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35062] RE: [mg35029] Re: [mg35005] Friendly Challenge 2: sort by column
  • From: "DrBob" <majort at cox-internet.com>
  • Date: Thu, 20 Jun 2002 23:55:30 -0400 (EDT)
  • Reply-to: <drbob at bigfoot.com>
  • Sender: owner-wri-mathgroup at wolfram.com

What do you mean by handling duplicates?  I THINK you mean keeping in
their preexisting order any rows that agree in the column you're sorting
by.

Your concern with the issue implies that Ordering doesn't preserve
existing order.  That's to be expected, I suppose, since preserving
order takes extra time and/or space -- but DOCUMENTATION SHOULD MAKE
THIS CLEAR from the start.  It's not always important for Sort
(depending on the sort function), but it's obviously important for
Ordering.

Bobby

-----Original Message-----
From: "Mr. Wizard" [mailto:gleam at flashmail.com] 
To: mathgroup at smc.vnet.net
Subject: [mg35062] [mg35029] Re: [mg35005] Friendly Challenge 2: sort by column

> consequently I should add 
> 
> (5) 
> 
> a[[Ordering[a[[All, 3]]]]] 

Hartmut Wolf, thank you for participating in this challenge.

Your #5 is one of the algorithms I'm using.  It's the fastest I've
found for sorting by one column only, disregarding the rest.

After moderate number of tests, not nearly up to your standards, but
enough to get a good start, I am prepared to observe that of your
functions that handle duplicates by using Rotate, your function #2 is
fastest.  (Incidentally, this is the duplicate handling method I first
chose, and still prefer.)  I have a function that, on my machine, is
usually faster than #2, sometimes considerably.  I have a feeling you
can best it if you try.

Examples:

hw2[a_,p_]:=RotateRight[Sort[RotateLeft[a,{0,p-1}]],{0,p-1}]

sort3[a_,p_]:= ??? (my function)

In[284]:=
a = Table[Random[Integer, {0, 255}], {37}, {50}];
First@Timing[Do[a~#~i, {i, 2, 50}]~Do~{70}] & /@ {sort3, hw2}

Out[285]=
{1.54 Second, 1.86 Second}

In[286]:=
a = Table[Random[], {500}, {300}];
First@Timing[Do[a~#~i, {i, 2, 299, 11}]] & /@ {sort3, hw2}

Out[287]=
{1.16 Second, 2.2 Second}

Regards,

Paul






  • Prev by Date: RE: Friendly Challenge 2: sort by column
  • Next by Date: Re: Odd Formatting Problem
  • Previous by thread: RE: Friendly Challenge 2: sort by column
  • Next by thread: RE: Re: Friendly Challenge 2: sort by column