We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Algorithm to shift each element of array by one position.
1. Store first element of input Arrays in C in a temporary variables in C(temp = inputArray[0]).
2. Starting from inputArray[1], shift all positions to left adjacent index(inputArray[i-1] = inputArray[i]).
3. Store temp value at last index of inputArray(inputArray[N-1] = temp). Time Complexity : O(n) Space Complexity : O(1)
Source : Array rotation by shifting elements
Here is the algorithm to rotate an array c program
Circular Array Rotation
You are viewing a single comment's thread. Return to all comments →
Algorithm to shift each element of array by one position.
1. Store first element of input Arrays in C in a temporary variables in C(temp = inputArray[0]).
2. Starting from inputArray[1], shift all positions to left adjacent index(inputArray[i-1] = inputArray[i]).
3. Store temp value at last index of inputArray(inputArray[N-1] = temp).
Time Complexity : O(n)
Space Complexity : O(1)
Source : Array rotation by shifting elements
Here is the algorithm to rotate an array c program