Services & Resources / Wolfram Forums
MathGroup Archive
*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
  • Subject: [mg35062] RE: [mg35029] Re: [mg35005] Friendly Challenge 2: sort by column
  • From: "DrBob" <majort at>
  • Date: Thu, 20 Jun 2002 23:55:30 -0400 (EDT)
  • Reply-to: <drbob at>
  • Sender: owner-wri-mathgroup at

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

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


-----Original Message-----
From: "Mr. Wizard" [mailto:gleam at] 
To: mathgroup at
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.



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

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

{1.54 Second, 1.86 Second}

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

{1.16 Second, 2.2 Second}



  • 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