Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 6th, 2006, 04:43 AM
GeorgeLiner GeorgeLiner is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 33 GeorgeLiner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 56 m 10 sec
Reputation Power: 3
How to transpose a matrix?

Hello everyone,


I am wondering how to transpose a matrix (m * n) with only constant space complexity O (1). (The transpose algorithm should execute/operate on the original matrix.)


thanks in advance,
George

Reply With Quote
  #2  
Old January 6th, 2006, 11:22 AM
codergeek42's Avatar
codergeek42 codergeek42 is offline
[Insert clever comment here.]
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jul 2003
Location: Anaheim, CA (USA)
Posts: 6,459 codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)codergeek42 User rank is General 4th Grade (Above 100000 Reputation Level)  Folding Points: 39542 Folding Title: Starter FolderFolding Points: 39542 Folding Title: Starter Folder
Time spent in forums: 1 Month 1 Week 6 Days 21 h 42 m 24 sec
Reputation Power: 1231
Send a message via ICQ to codergeek42 Send a message via AIM to codergeek42 Send a message via Yahoo to codergeek42 Send a message via Google Talk to codergeek42
Erm, O(1) matrix transposing is completely impossible. O(1) means that the algorithm would run in a constant time, regardless of the size of the input matrix.

Are you sure you don't mean O(n)? That would mean that the time it takes the algorithm to run has a strictly linear correlation with the input matrix's size.

Also note that copying a matrix is also an O(n) algorithm, so, strictly speaking, copying the input elements to temporary matrix in transposed order, and assigning the referenced input matrix to the resulting matrix would still be O(n).

Hope that helps.
__________________
~~ Peter ~~
( My Blog: It's exactly like normal nerdiness, but completely different. ) :: ( Supporter of the EFF & FSF ) :: ( I'm a GNU/Linux addict and Free Software Advocate. ) :: ( How to Ask Questions the Smart Way ) :: ( The Fedora Project, sponsored by Red Hat ) :: ( GNOME: The Free Software Desktop Project ) :: ( GnuPG Public Key )

Reply With Quote
  #3  
Old January 7th, 2006, 02:33 AM
GeorgeLiner GeorgeLiner is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 33 GeorgeLiner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 56 m 10 sec
Reputation Power: 3
codergeek42,


Quote:
Originally Posted by codergeek42
Erm, O(1) matrix transposing is completely impossible. O(1) means that the algorithm would run in a constant time, regardless of the size of the input matrix.

Are you sure you don't mean O(n)? That would mean that the time it takes the algorithm to run has a strictly linear correlation with the input matrix's size.

Also note that copying a matrix is also an O(n) algorithm, so, strictly speaking, copying the input elements to temporary matrix in transposed order, and assigning the referenced input matrix to the resulting matrix would still be O(n).

Hope that helps.


Thank you very much for your comments. In my question, I mean space complexity is O(1) -- not time complexity.

Anyway, do you have any good ideas?


regards,
George

Reply With Quote
  #4  
Old January 8th, 2006, 01:28 PM
tragen tragen is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 7 tragen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 44 sec
Reputation Power: 0
The are alot of good packages out there that does this for you, for example in java there is the Jama package.. I would say google that and look at the algorithims yoruself.



Quote:
Originally Posted by GeorgeLiner
codergeek42,




Thank you very much for your comments. In my question, I mean space complexity is O(1) -- not time complexity.

Anyway, do you have any good ideas?


regards,
George

Reply With Quote
  #5  
Old January 9th, 2006, 03:29 AM
GeorgeLiner GeorgeLiner is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 33 GeorgeLiner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 56 m 10 sec
Reputation Power: 3
tragen,


Quote:
Originally Posted by tragen
The are alot of good packages out there that does this for you, for example in java there is the Jama package.. I would say google that and look at the algorithims yoruself.


Thank you very much for providing the information. I have read related information from JAMA,

http://math.nist.gov/javanumerics/jama/

I am not sure whether the matrix transposition implementation of Jama package requires only constant additional space complexity O(1). Are you sure about that?


regards,
George

Reply With Quote
  #6  
Old January 10th, 2006, 11:52 PM
Lux Perpetua Lux Perpetua is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: San Francisco Bay
Posts: 1,475 Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level)Lux Perpetua User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 19 m 53 sec
Reputation Power: 377
If the matrix is stored as a 2-dimensional array M, then transposing just means M[i][j] is set to M[j][i] and vice versa for all i and j within the dimensions. The basic operation is just a swap: t = M[i][j]; M[i][j] = M[j][i]; M[j][i] = t. Iterate over all (i, j) with i < j and you're done. The only space overhead is the temporary variable t and the variables i and j controlling your loops, i.e., constant space complexity.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > How to transpose a matrix?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT