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: Friendly Challenge 2: sort by column

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35029] Re: [mg35005] Friendly Challenge 2: sort by column
  • From: gleam at flashmail.com ("Mr. Wizard")
  • Date: Thu, 20 Jun 2002 02:13:34 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

> 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: Solve weirdness
  • Next by Date: Odd Formatting Problem
  • Previous by thread: Friendly Challenge 2: sort by column
  • Next by thread: Re: Friendly Challenge 2: sort by column