What is the fastest algorithm for circle shifting array for M positions?
For example, [3 4 5 2 3 1 4] shift M = 2 positions should be [1 4 3 4 5 2 3
Depending on the data structure you use, you can do it in O(1). I think the fastest way is to hold the array in the form of a linked list, and have a hash table that can translate between "index" in the array to "pointer" to the entry. This way you can find the relevant heads and tails in O(1), and do the reconnection in O(1) (and update the hash table after the switch in O(1)). This of course would be a very "messy" solution, but if all you're interested in is the speed of the shift, that will do (on the expense of longer insertion and lookup in the array, but it will still remain O(1))
If you have the data in a pure array, I don't think you can avoid O(n).
Coding-wise, it depends on what language you are using.
In Python for example, you could "slice" it (assume n is the shift size):
result = original[-n:]+original[:-n]
(I know that hash lookup is in theory not O(1) but we're practical here and not theoretical, at least I hope so...)