What is the difference between rotating an array to the right by k positions and cyclically shifting it, and how do you compute the effective k?
Rotating to the right by k places means that the last k values move to the front, and the order of everything is kept. A cyclic shift is the same thing seen as a circle, and that is how you work out the effective number of places to move.
So how do you work out the effective k? You take the remainder when you divide k by the length of the list. That is because going round the list once changes nothing, so five places on a list of three is the same as two places.
the length is 5 and k is 2 the result
------------------------------ --------------------
2 the last two move to the front
7 the same as 2
12 the same as 2
And you have to take the remainder before you do anything else, because a value of k that is bigger than the length is the normal case rather than an unusual one. You also have to handle the case where the list is empty, because then there is nothing to rotate and the division would not work at all.
So the rule to remember is this. Take k modulo the length first, and then move that many values from the back to the front.
The next two questions in this topic show the in-place version and the short version.