Subj : Re: Faster matrix permutation algorithm? To : comp.lang.c,comp.programming From : Michael Mair Date : Sat Aug 13 2005 03:09 pm Jack Middleton wrote: > I'm lookin for a faster permutation algorithm for matrices. I know that > it can be done with multiplying a matrix with a permutation matrix. It > just seems a waste to iterate through all those zeroes. Is there an > algorithm for matrixes that is optimized just for permutations? The > matrices that I use are fairly small (around 6*6) and I only use > positive integers as elements. Note that this is off-topic in comp.lang.c from where I am posting. -> f'up2c.p Some thoughts on your question: - Do you want to restrict yourself to certain classes of permutations or do you just want the matrix elements reordered in a random way? - In the latter case, if you are programming in a language where you know the memory layout and where the memory layout of the matrix is essentially an array, you can just use (perfect) shuffling -- or, if you need all permutations, a loop through all array permutations. - Otherwise, just perform the effective action of the matrix-matrix multiplication: Interchange the rows/columns of the target matrix as intended. Cheers Michael -- E-Mail: Mine is an /at/ gmx /dot/ de address. .