(1) Implement the function by allocating a new n X n 2D array. Then write the rotation to it by writing the rows of the original matrix to the columns in the solution matrix such that they fit the solution requirement. Then copy the new matrix exactly the same to the original matrix so that you know for sure you have updated the original matrix to look modified. (2) Implement the function by not allocating a new n Xn 2D array.
java
(1) Implement the function by allocating a new n X n 2D array.
Then write the rotation to it by writing the rows of the original matrix to
the columns in the solution matrix such that they fit the solution require[1]ment. Then copy the new matrix exactly the same to the original matrix
so that you know for sure you have updated the original matrix to look
modified.
(2) Implement the function by not allocating a new n X n 2D
array.
Hint : Perform the rotation in a layer by layer fashion - meaning - different layers can be processed independently. Also within a layer, you
can exchange groups of four elements at a time to perform the rotation.
Example : Send 1 to 4’s location, 4 to 16’s location, 16 to 13’s location
and 13 to 1’s location.
Ungraded but Important : As a comment in your code for Problem 2,
write your observation on the different solutioning methods utilized.
should speak in terms of Time and Space Complexity. Which solution
does what in terms of time and space. Which is better, which is worse.
Which solution would you prefer and why? observation should be
no more than 5 lines :)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images