Hi,

 

I'm idling today, it's my last day in China and I'm going home to the
Philippines tomorrow, so it really safe to stop reading now and do some
other stuff. J

 

So there was this discussion in the Programming list about sorting. So I
thought about how I actually do sorting which is this way:

NB. Generate 1,048,576 of random numbers

   $v=: (1024 * 1024) [EMAIL PROTECTED]

1048576

NB. Time how fast and how much space

   timespacex 'v{~/:v'

0.0476471870028174 25166528

 

Now I know that there is another method called quick sort which is
defined this way,

NB. quicksort as defined in
http://jsoftware.com/help/dictionary/d212.htm

   quicksort=: (($:@(<#[) , (=#[) , $:@(>#[)) ({~ [EMAIL PROTECTED])) ^: (1<#)

NB. Find the time and space consumed

   timespacex 'quicksort v'

0.364349728806315 27556096

 

As you can see, the first one runs faster and eats lesser memory. There
are always a lot of ways to get to the correct answer when you're using
J. J

 

r/Alex

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to