Re: [algogeeks] Re: rotate a matrix NVIDIA question

2011-07-28 Thread Tushar Bindal
thanks amit for this code i tried this for the first time and am still not over finding out my mistakes (got another one while trying it out on an array) yours was an easy one :) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to thi

Re: [algogeeks] Re: rotate a matrix NVIDIA question

2011-07-28 Thread Tushar Bindal
i am sorry for givin such a naive solution and making so many mistakes. i still left a mistake in dir==4 * col=n-1-(col+1);* -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To u

Re: [algogeeks] Re: rotate a matrix NVIDIA question

2011-07-28 Thread Tushar Bindal
There will be following changes to this while(noOfCellsVisitedhttp://groups.google.com/group/algogeeks?hl=en.

[algogeeks] Re: rotate a matrix NVIDIA question

2011-07-28 Thread amit karmakar
I think you meant spiral traversal, #include #include using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) const int MX = 1000; int a[MX][MX], seen[MX][MX], n; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; int main() { scanf("%d", &n); REP(i, n) REP(j, n) scanf("%d

Re: [algogeeks] Re: rotate a matrix NVIDIA question

2011-07-28 Thread Tushar Bindal
If this is the case, we can follow this method: take variables 1. dir = 1 2. st_col=0 3. end_col = n-1 4. st_row = 1 5. end_row = n-1 6. row = 0 7. col = n-1 8. noOfCellsVisited = 0 dir are as follows: 1 - left ro right 2 - top to bottom 3 - right to left 4 - bottom to top row will keep account

Re: [algogeeks] Re: rotate a matrix NVIDIA question

2011-07-28 Thread Tushar Bindal
I think that we have to make a spiral traversal So o/p for your matrix would be: 1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5, 6, 7, 11, 10 On Thu, Jul 28, 2011 at 1:56 PM, Rajeev Kumar wrote: > @puneet > > Can you give us an example what u mean by 180 degree rotation... > For given matrix lik

Re: [algogeeks] Re: rotate a matrix NVIDIA question

2011-07-28 Thread Rajeev Kumar
@puneet Can you give us an example what u mean by 180 degree rotation... For given matrix like 1, 2, 3, 4 5, 6, 7, 8 9,10,11, 12 13,14,15,16 What is the expected output? On Wed, Jul 27, 2011 at 11:29 PM, Puneet Gautam wrote: > Can anyone give an O(n) solution pls...?? > I t

Re: [algogeeks] Re: rotate a matrix NVIDIA question

2011-07-27 Thread Deoki Nandan
there is no specification on complexity . if input matrix is 1 2 3 4 5 6 7 8 9 then after 180 rotation output should be 1 2 3 6 9 8 7 4 5 On Wed, Jul 27, 2011 at 11:34 PM, amit karmakar wrote: > If you meant "rotate a 2D matrix by angle 180" of order n x n > Then you cannot have a O(n) algo, Eac

[algogeeks] Re: rotate a matrix NVIDIA question

2011-07-27 Thread amit karmakar
If you meant "rotate a 2D matrix by angle 180" of order n x n Then you cannot have a O(n) algo, Each of the n^2 elements must be accessed so you cannot have anything less than n^2 On Jul 27, 10:59 pm, Puneet Gautam wrote: > Can anyone give an O(n) solution pls...?? > I think the above code is an

Re: [algogeeks] Re: rotate a matrix NVIDIA question

2011-07-27 Thread Puneet Gautam
Can anyone give an O(n) solution pls...?? I think the above code is an O(n^2) solution.. if i am not wrong...!!! On 7/27/11, amit wrote: > #include > #include > using namespace std; > > const int MX = 1000; > int n, m; > int a[MX][MX]; > > int main() { > scanf("%d%d", &n, &m); > for(i

[algogeeks] Re: rotate a matrix NVIDIA question

2011-07-27 Thread amit
#include #include using namespace std; const int MX = 1000; int n, m; int a[MX][MX]; int main() { scanf("%d%d", &n, &m); for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) scanf("%d", &a[i][j]); for(int i = 0; i < n/2; i++) for(int j = 0; j < m; j++)