Subject: matrix transpose (was Re: mini / maxi functions)
From: Barton Willis
Date: Sun, 27 Jun 2010 06:57:25 -0500
For a n x n matrix, the running time for transpose is O(n^3). Here is a proposed O(n^2) replacement:
;; Transpose a list of lists ll and return a list of lists. Example:
;; ((1 2) (3 4)) --> ((1 3) (2 4)).
(defun transpose (ll)
??(let ((acc nil))
?? ?(while (car ll)
?? ? ?(push (mapcar #'car ll) acc)
?? ? ?(setq ll (mapcar #'cdr ll)))
?? ?(nreverse acc)))
To transpose the 800 x 800 matrix (i,j) --> i - j:
??current transpose: ?26.21 seconds
??proposed transpose: ?0.80 seconds.
Matrix multiplication also uses transpose.
Comments?
--Barton