A better (x3 faster and x2 leaner) "merge" is 
   /:~@, 

However, the merge below is for sorting algorithm,
which must not use /:~ sort itself. Dyad /: is merely
a selection operation.

Merge below is faster if X <&# Y. 

It could be theoretically still faster, 
if I. "knew" that Y is sorted (by rank it sees 
all items of Y). Maybe it already does?
However, such discovery could be costly.

--- On Tue, 4/29/08, Oleg Kobchenko <[EMAIL PROTECTED]> wrote:

Related to recent discussion of sorting algorithms, there is one 
called Merge Sort. It depends on the operation of merging two 
sorted lists. Merge can be thought of as bulk insert. 
I was thinking of effective ways to do merge in J, 
when the post from Roger came and broght along the
idea of using /: which is perfect in combination with 
I. interval index.

   merge=: , /: I. ,~ 1 + [EMAIL PROTECTED]@[

   'A B'=: /:~&.> 4 ({.;}.) 10 [EMAIL PROTECTED] 10
   
   A
2 5 6 9
   B
0 0 4 4 7 9
   
   A merge B
0 0 2 4 4 5 6 7 9 9
   B merge A
0 0 2 4 4 5 6 7 9 9

Again, please see if this can be improved.




      
____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to