wu :: forums
« wu :: forums - Convert Row Major rep to Column Major rep »

Welcome, Guest. Please Login or Register.
Apr 17th, 2025, 11:24am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: william wu, ThudnBlunder, Eigenray, Icarus, towr, Grimbal, SMQ)
   Convert Row Major rep to Column Major rep
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Convert Row Major rep to Column Major rep  (Read 2834 times)
sateesp
Newbie
*





   


Gender: male
Posts: 35
Convert Row Major rep to Column Major rep  
« on: Aug 22nd, 2010, 3:53am »
Quote Quote Modify Modify

Given M*N matrix is represented in row major fashion in single dimension array. Write a Algo to convert this array into column major way of representation of matrix.
Example:  Given matrix
1 2 3 4
5 6 7 8  
and array connects are  1 2 3 4 5 6 7 8. Now we need to convert to 1 5 2 6 3 7 4 8
IP Logged
towr
wu::riddles Moderator
Uberpuzzler
*****



Some people are average, some are just mean.

   


Gender: male
Posts: 13730
Re: Convert Row Major rep to Column Major rep  
« Reply #1 on: Aug 22nd, 2010, 6:38am »
Quote Quote Modify Modify

Do you want to rearrange it in the same memory without using extra memory to do so?
IP Logged

Wikipedia, Google, Mathworld, Integer sequence DB
sateesp
Newbie
*





   


Gender: male
Posts: 35
Re: Convert Row Major rep to Column Major rep  
« Reply #2 on: Aug 22nd, 2010, 10:44am »
Quote Quote Modify Modify

yes towr.
IP Logged
TenaliRaman
Uberpuzzler
*****



I am no special. I am only passionately curious.

   


Gender: male
Posts: 1001
Re: Convert Row Major rep to Column Major rep  
« Reply #3 on: Aug 23rd, 2010, 7:01am »
Quote Quote Modify Modify

No extra memory might be a bit harsher restriction as per [1] (for arbitrary rectangular matrices).
 
However, it is possible to do in-place transposition for square matrices with no extra memory [1].  
 
If you allow for O(1) memory at least, then there are some neat cycle based algorithms given in [1].
 
-- AI
[1] http://en.wikipedia.org/wiki/In-place_matrix_transposition
« Last Edit: Aug 23rd, 2010, 7:32am by TenaliRaman » IP Logged

Self discovery comes when a man measures himself against an obstacle - Antoine de Saint Exupery
sateesp
Newbie
*





   


Gender: male
Posts: 35
Re: Convert Row Major rep to Column Major rep  
« Reply #4 on: Aug 23rd, 2010, 9:19am »
Quote Quote Modify Modify

Yes, constant space is allowed.  
@TenaliRaman,I just saw wiki link you provided. It has very good explanation.  Thanks.
IP Logged
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board