We will left rotate the array by 3
places using the reversal algorithm.
{ "array": [10,20,30,40,50,60,70], "showIndices": true }
Step 1: Reverse the first 3
elements.
{ "array": [10,20,30,40,50,60,70], "showIndices": true, "labels": { "0": "start", "2": "end" }, "highlightIndices": [0,1,2] }
{ "array": [30,20,10,40,50,60,70], "showIndices": true, "labels": { "0": "start", "2": "end" } }
Step 2: Reverse the remaining 4
elements.
{ "array": [30,20,10,40,50,60,70], "showIndices": true, "labels": { "3": "start", "6": "end" }, "highlightIndices": [3,4,5,6] }
{ "array": [30,20,10,70,60,50,40], "showIndices": true, "labels": { "3": "start", "6": "end" } }
Step 3: Reverse the entire array.
{ "array": [30,20,10,70,60,50,40], "showIndices": true, "labels": { "0": "start", "6": "end" }, "highlightIndices": [0,1,2,3,4,5,6] }
{ "array": [40,50,60,70,10,20,30], "showIndices": true, "labels": { "0": "start", "6": "end" } }
Final Rotated Array:
{ "array": [40,50,60,70,10,20,30], "showIndices": true, "highlightIndicesGreen": [4,5,6] }
Comments
Loading comments...