Thursday, December 18, 2008

Array Rotation

A[M][N] is an array rotated in anti clock wise that is A'[N][M]. then mapping A[j]=A'[ _ ][ _ ] in terms of M,N

A
1 2 3
4 5 6

A'
3 6
2 5
1 4


A[j]=A'[ _ ][ _ ] ??


Solution:


i' = N-j-1
j' = i
thus after rotation
A'[i ][j] = A[N-j-1][ i]

No comments:

Post a Comment